【发布时间】:2016-11-26 00:32:00
【问题描述】:
我在表格单元格中有一个按钮,当按下它时,应用程序会因错误而崩溃:
无法识别的选择器发送到实例 0x7f9a39840a00 2016-11-25 15:32:04.310 应用程序名称 [19161:1264937] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[App_Name.routineCell forwardPress:]:无法识别的选择器发送到实例 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吗? -
selector方法必须在target指定的类中实现。self是当前类。要么实现routineCell中的方法,然后更改目标或更改选择器。除此之外,以小写字母开头的命名类非常混乱。 -
@ArtemNovichkov 有一点 - 错误不是来自给定的代码。在其他地方,你一定是打电话给
forwardPress:。 -
@ganzogo 我没有调用 forwardPress: 代码中的任何地方 - 唯一出现的地方是错误
-
是否有可能从您的依赖项之一调用它?如果没有,那我就难住了。