【发布时间】:2016-11-22 16:00:25
【问题描述】:
ViewController 中有一个 TableView。TableViewCell 有一个带有一些内容的 textView。现在单击cell 中的replyButton 后,segue 到secondViewController。我需要将内容放在cell 的textView 中。怎么做?我使用indexPath 作为下面的代码,但它崩溃了,因为indexPath 是nil。感谢您的帮助。
澄清:我需要点击单元格内的replyButton来实现目标,而不是使用didSelectRowAtIndexPath函数。
代码:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBAction func replyButtonTapped(_ sender: Any) {
self.performSegue(withIdentifier: "toReplyVC", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toReplyVC" {
let replyVC = segue.destination as! ReplyVC
// code below did't work:
/*
let indexPath = self.repliesTableView.indexPathForSelectedRow
let cell = self.repliesTableView.cellForRow(at: indexPath!) as! ReplyCell
replyVC.replyQuote = cell.replyTextView.text
*/
}
}
}
【问题讨论】:
-
是否有任何崩溃报告或只是值 nil ?给我们一些关于您的问题的解释。
-
因为 indexPath 为 nil 而崩溃。
标签: swift uitableview segue