ViewController
有TableView
。 TableViewCell
有一個textView與一些內容。在cell
,segue
到secondViewController
之間點擊replyButton
後。我需要將內容放入cell
的textView
。怎麼做?我使用indexPath
作爲下面的代碼,但它崩潰,因爲indexPath
是nil
。感謝您的幫助。單擊UITableviewCell中的按鈕後如何傳遞值?
說明:我需要單擊單元格內的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?給我們一些關於你的問題的解釋。 – emresancaktar
墜毀,因爲indexPath爲零。 – developermike