【发布时间】:2017-07-31 10:09:34
【问题描述】:
基本上,我正在尝试传递/使用我已经从 Firebase 获取的单元格实例(label.text)并将其分配给目标 chatViewController 变量
我相信我遇到了 segue 的问题,在调试我的代码后,segue 不会以这种方式传递数据:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // 2
return users.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.nameLblCell.text = users[indexPath.row].name
cell.emailLblCell.text = users[indexPath.row].email
cell.profilePictureCell.downloadImage(from: users[indexPath.row].proPicURL)
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let instance = TableViewCell()
let chatVc = segue.destination as? ChatViewController
chatVc?.reciverImageVariable = instance.profilePictureCell.image!
chatVc?.destinationEmail = instance.emailLblCell.text!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let userId = users[indexPath.row].id
self.performSegue(withIdentifier: "ShowChatView", sender: userId)
}
【问题讨论】:
-
在prepareforSegue中,访问选中的单元格为 let indexPath = tableView.indexPathForSelectedRow() let instance = tableView.cellForRowAtIndexPath(indexPath) as UITableViewCell
-
let instance = TableViewCell()你正在创建一个全新的单元格。相反,使用tableView.selectedIndexPath()检索indexPath,然后使用user[thatIndexPathSelected.row]。 -
你已经尝试使用导航控制器@OT AMD
标签: ios swift uitableview segue