ios - UITableViewCell 问题中的 UIButton:无法识别选择器
问题描述
所以我一直在搜索 StackExchange 如何将 UIButton 放在 UITableViewCell 中,并认为我找到了答案,但一直"unrecognized selector sent to instance"
出错。
这是我调用函数的地方
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tblTeams.dequeueReusableCell(withIdentifier: "cellReuse")! as! TeamsTableViewCell
cell.btnLeave.tag = indexPath.row
cell.btnLeave.addTarget(self, action: "LeaveTeam:", for: UIControlEvents.touchUpInside)
return cell
}
这就是功能所在。它与前面的代码块在同一类甚至扩展中
@IBAction func LeaveTeam(sender: UIButton){
}
我试过改写报价,我试过使用#selector
......请告诉我我是如何做对的。谢谢!
解决方案
代替
cell.btnLeave.addTarget(self, action: #selector(leaveTeam(_:)) for: UIControlEvents.touchUpInside)
@objc func leaveTeam(_ sender: UIButton) {---}
小写开始方法名
推荐阅读
- javascript - 如何在特定行上启用点击操作?
- android - 上传到 Google Play 时 Google Plus 登录失败
- python - 无法格式化打印字符串
- database - 在 Eloquent 中加入多对多关系
- react-native - 使用反应原生路由器通量在表示组件中识别右上角的按钮单击
- c# - 通过 C# 套接字推送通知
- database - 单表继承会导致非规范化吗
- android - 如何通过水平跨度实现水平网格回收器视图
- html - 使用 MathJax 生成 Sigma 问题(1 次成功和 1 次失败)
- javascript - JavaScript 函数,与函数参数相关的错误