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
은 indexPath가 nil이므로 오류가 발생했습니다. – developermike