我遇到从表视图控制器移动到视图控制器以显示有关所选特定单元格的信息的问题。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SentDetailView" {
let indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow! as NSIndexPath
let referrals = referralsSent[indexPath.row]
let destViewController = segue.destination as! SentDetailViewController
destViewController.referringTo = referrals.referTo
destViewController.patientsName = referrals.patientsName
//print("Contained value during segue " + destViewController.patientsName!)
destViewController.patientsPhoneNumber = referrals.patientsNumber
destViewController.patientsEmail = referrals.patientsEmail
destViewController.comments = referrals.comment
}
}
故事板设置:
我得到以下结果:
我选择了一个单元格,它只是突出显示并且没有做任何事情。
答案 0 :(得分:0)
您应该覆盖didSelectRowAt
并使用发件人作为选定的索引路径调用performSegue
。试试这个。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "SentDetailView", sender: indexPath)
}
而且这个。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SentDetailView"{
let indexPath = sender as! IndexPath
let referrals = referralsSent[indexPath.row]
let destViewController = segue.destination as! SentDetailViewController
destViewController.referringTo = referrals.referTo
destViewController.patientsName = referrals.patientsName
//print("Contained value during segue " + destViewController.patientsName!)
destViewController.patientsPhoneNumber = referrals.patientsNumber
destViewController.patientsEmail = referrals.patientsEmail
destViewController.comments = referrals.comment
}
}