从特定行设置动态自定义单元格

Set dynamic Custom Cell from certain row

我正在开发一个社交功能,人们可以在其中对图片发表评论。 唯一的动态单元格也是评论单元格。我正在为此使用 Parse。

如何在每个评论单元格上获得不同的评论? 我尝试访问 indexPath.row,但出现错误:'*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'

现在使用自定义 NSIndexPath 但我只能手动访问 forRow 方法。结果评论都一样

发生这种情况是因为在你的最后一点中你总是在解析中请求第 0 行第 0 节,你将需要这样的东西:

else {
let commentCell:commentTableViewCell = tableView.dequeueReusableCellWithIdentifier("commentCell") as commentTableViewCell

//indexPath.row is the actual row of the table, 
//so you will have for table row 2 parse row 0, for 3 row 1 and so on
let commentIndex:NSIndexPath = NSIndexPath(forRow: indexPath.row-2, inSection: 0)
let comment:PFObject = userComments.objectAtIndex(commentIndex.row) as PFObject

println(comment)

// Comment Label
commentCell.commentLabel.text = comment.objectForKey("content") as String!
commentCell.userImageView.image = UIImage(named: "dummy")

return commentCell
}