我的表格单元格中有一个按钮,按下时它会使应用程序崩溃并出现错误:
unrecognized selector sent to instance 0x7f9a39840a00 2016-11-25 15:32:04.310 App Name[19161:1264937] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[App_Name.routineCell forwardPress:]: unrecognized selector sent to instance 0x7f9a39840a00'
代码如下:
internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return routineGroups.count
}
func cellButtonPress() {
print("works")
}
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell:routineCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! routineCell
cell.textLabel?.text = routineGroups[indexPath.row]
cell.forwardButton.tag = indexPath.row
cell.forwardButton.addTarget(self, action: #selector(routinesGroups.cellButtonPress), for: UIControlEvents.touchUpInside)
return cell
}
我在这里查看了解决方案:Link1在这里 Link2但我每次都会遇到同样的错误。 该单元格有自己的 .swift 文件,将其作为导出拖动: Cell.swift file
当崩溃发生时,Xcode 将我带到 AppDelegate.swift 并显示:crash goto
有人知道如何解决这个问题吗?
最佳答案
问题似乎是关于 forwardPress
,而不是 forwardButton
或 cellButtonPress
。您检查过 Interface Builder 中的 Outlet Inspector 了吗?
在某些界面元素(可能是读取调试器时的单元格)上,您可能有一个未在名为 forwardPress
的代码中链接的 socket 。您对元素执行操作,IB 会查找 forwardPress
方法,该方法不存在 => 崩溃。
关于ios - 表格单元格中的 UIButton "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40808458/