![](/img/trans.png)
[英]How to add a button with click event on UITableViewCell in Swift?
[英]how to add popover segue from UITableViewCell button click in swift 3.0?
在这里,我通过单击UITableVIewCell按钮将弹出框用于新的ViewController,但出现此错误Main.storyboard:无法编译连接:property = anchorView destination =>
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(tableView == self.table_view_one) {
var cell = table_view_one.dequeueReusableCell(withIdentifier: "first_cell", for: indexPath) as! first_cell
cell.first_view_time_btn.addTarget(self, action: #selector(Iop_gonio_ViewController.someAction), for: .touchUpInside)
return cell
}
}
func someAction() {
self.performSegue(withIdentifier: "first_time_btn", sender: self)
}
尝试
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(tableView == self.table_view_one) {
var cell = table_view_one.dequeueReusableCell(withIdentifier: "first_cell", for: indexPath) as! first_cell
cell.first_view_time_btn.addTarget(self, action: #selector(someAction(sender:)), for: .touchUpInside)
return cell
}
func someAction(sender:UIButton) {
self.performSegue(withIdentifier: "first_time_btn", sender: self)
}
但是我认为这不是一个好方法,您应该创建一个协议来处理这种交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.