因此,我一直在搜索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
...请告诉我如何正确处理。谢谢!
答案 0 :(得分:1)
替换
cell.btnLeave.addTarget(self, action: #selector(leaveTeam(_:)) for: UIControlEvents.touchUpInside)
@objc func leaveTeam(_ sender: UIButton) {---}
小写的启动方法名称
答案 1 :(得分:0)
addTarget(self, action:#selector(leaveTeam(sender:)), for: .touchUpInside)
@objc func leaveTeam(sender : UIButton) -> Void {
}