[英]Tableview passing same data on select
I have a tableview that display a list of Parse users by object Id. 我有一个表格视图,按对象ID显示分析用户列表。 I am trying to have it so when tapped it will push you to a new view controller, with that corresponding objectId. 我正在尝试使用它,因此在点击它时会将您推送到具有相应objectId的新视图控制器。 I have the objectId's printing fine in the cell, and even passing data to the new view controller, but it only is passing the last objectId pulled from the query. 我在单元格中可以很好地打印objectId,甚至可以将数据传递到新的视图控制器,但是它只是传递从查询中拉出的最后一个objectId。 If someone can help me figure out how to send that rows objectId that would be helpful. 如果有人可以帮助我弄清楚如何发送该行objectId会很有帮助。 Here is my code: 这是我的代码:
@IBOutlet weak var objectIdData: UILabel!
internal func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:ChatTableCell = self.tableView.dequeueReusableCellWithIdentifier("ChatCell") as! ChatTableCell
let user = self.friends[indexPath.row]
self.objectIdData?.text = String(user.objectId!)
cell.cellTitle?.text = String(user.objectId).uppercaseString
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
let user = self.friends[indexPath.row]
let secondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("DetailViewController") as! DetailViewController
secondViewController.lblDetail = objectIdData
self.navigationController!.pushViewController(secondViewController, animated: true)
}
So it passes the objectId to the lblDetail on the next view controller, but always the same objectId, not the one associated with that user/row. 因此,它将objectId传递给下一个视图控制器上的lblDetail,但始终是相同的objectId,而不是与该用户/行关联的对象。 Thanks in advance. 提前致谢。
In didSelectRowAtIndexPath
, you are setting a UI element (objectIdData isa UILabel) on the secondViewController
. 在didSelectRowAtIndexPath
,您要在secondViewController
上设置UI元素(objectIdData isa UILabel)。
I believe you just want to set the text of the lblDetail
just like you did in cellForRowAtIndexPath
. 我相信您只想像在cellForRowAtIndexPath
一样设置lblDetail
的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.