ios - Tableview 在选择上传递相同的数据

标签 ios swift uitableview

我有一个表格 View ,它按对象 ID 显示 Parse 用户列表。我试图拥有它,这样当点击它时,它会将您推送到一个新的 View Controller ,并带有相应的 objectId。我在单元格中可以很好地打印 objectId,甚至可以将数据传递到新的 View Controller ,但它只是传递从查询中提取的最后一个 objectId。如果有人可以帮助我弄清楚如何发送该行 objectId 那会很有帮助。这是我的代码:

@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)

}

因此它将 objectId 传递给下一个 View Controller 上的 lblDetail,但始终是相同的 objectId,而不是与该用户/行关联的 objectId。提前致谢。

最佳答案

didSelectRowAtIndexPath 中,您正在 secondViewController 上设置 UI 元素(objectIdData 是 UILabel)。

我相信您只想设置 lblDetail 的文本,就像在 cellForRowAtIndexPath 中所做的那样。

关于ios - Tableview 在选择上传递相同的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39496998/

相关文章:

ios - 使用 UIRefreshControl 在 UITableView 中禁用底部反弹

iphone - 从另一个类调用类方法?

swift +核心数据: Unable to add managed object after generating its subclass in swift

ios - iPhone - 使用 Swift 播放 mp4 视频时出现问题 - iOS

ios - 无法识别的选择器发送到实例 tableview swift

python - 在 Swift 中测量 http HEAD 请求的响应时间

ios - Tableview 动态开关有问题,如果我选择开关并立即打开它,它不会快速打开

ios - 为什么 tableView reloadData 不调用 cellForRowAtIndexPath

iOS 系统图标不尊重 UIButton 的 UIImageInsets

ios - 非常意外的未包装零值