0
我正在製作一個社交功能,讓人們可以在圖片上發表評論。 唯一的動態單元格也是註釋單元格。我爲此使用了Parse。從某一行設置動態自定義單元格
如何在每個評論單元上獲得不同的評論? 我試圖訪問indexPath.row,但它給了我一個錯誤:'*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
現在有了自定義NSIndexPath
打不過我只設法手動存取權限的forRow
方法。結果是評論都是一樣的。
- 行0 & 1正在工作。
- 使用故事板。
userComments
是正在加載註釋的可變數組。println(comments)
給我2個相同的物體。override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ return userComments.count + 2 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { if indexPath.row == 0 { let Postcell:PostTableViewCell = tableView.dequeueReusableCellWithIdentifier("imageCell") as PostTableViewCell .... return Postcell } if indexPath.row == 1 { let likeCell:likedTableViewCell = tableView.dequeueReusableCellWithIdentifier("likeCell") as likedTableViewCell .... return likeCell }else { let commentCell:commentTableViewCell = tableView.dequeueReusableCellWithIdentifier("commentCell") as commentTableViewCell let commentIndex:NSIndexPath = NSIndexPath(forRow: 0, 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 } }
你的要命!感謝您的好解釋! – SwingerDinger 2015-02-11 11:15:58
你很好:) – 2015-02-11 12:04:24