如何通过表格视图单元格中的按钮来选择新的视图控制器?我需要发送一些数据,所以不确定我是否可以从tableViewCell类中完成该操作。
答案 0 :(得分:1)
尝试
var profilePressed: ((UITableViewCell) -> Void)?
@IBAction func profileNamePressed(_ sender: Any) {
profilePressed?(self)
}
在表格视图单元格类中,以及此:
cell.profilePressed = { (cell) in
let profileVC = self.storyboard?.instantiateViewController(withIdentifier: "ProfileVC") as! ProfileVC
profileVC.initData(withPostedBy: message.postedBy)
self.presentDetail(profileVC)
}
在单元格中的索引路径功能处排
答案 1 :(得分:0)
像这样构造自定义单元格
class MyCell:UITableViewCell {
weak var delegate:VCName?
@IBAction func btnClicked(_ sender:UIButton) {
delegate?.performSegue(withIdentifier:"segue",sender:someValue)
}
}
在vc的cellForRowAt
let cell = ///
cell.delegate = self