ViewController
にTableView
があります。 TableViewCell
にはいくつかの内容のtextViewがあります。今すぐcell
のreplyButton
をクリックした後、segue
〜secondViewController
をクリックします。 cell
のtextView
にコンテンツを配置する必要があります。どうやってするの?私はindexPath
を以下のコードとして使用しましたが、indexPath
がnil
であるため、クラッシュしました。助けてくれてありがとう。UITableviewCellのボタンをクリックした後に値を転送する方法は?
明確化:didSelectRowAtIndexPath関数を使用するのではなく、目標を実現するためにセル内のreplyButtonをクリックする必要があります。
コード:テキスト値を取得しようとしている方法とあまり間違ってないです
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
がクラッシュしました。 – developermike