【发布时间】:2017-08-16 11:18:55
【问题描述】:
当用户单击表格视图单元格中的按钮时,我试图做到这一点,它将他们带到与当前单元格相关的新视图控制器。
【问题讨论】:
当用户单击表格视图单元格中的按钮时,我试图做到这一点,它将他们带到与当前单元格相关的新视图控制器。
【问题讨论】:
试试下面的代码,
在 cellForRowAt indexPath 中执行此操作,
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell_Identifier", for: indexPath) as! UITableViewCell
cell.myButton.isUserInteractionEnabled = true
cell.myButton.tag = indexPath.row
cell.myButton.addTarget(self, action: #selector(didTapMyButton(_:)), for: UIControlEvents.touchUpInside)
return cell
}
这是按钮操作,
func didTapMyButton(_ sender : UIButton) {
let selectedIndex = sender.tag // You can get index here, so according to the index you can navigate to particular ViewController
let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "UIViewController_identifier") as! UIViewController
self.present(nextVC, animated: true, completion: nil)
}
希望对你有帮助..
【讨论】: