【问题标题】:Unrecognized selector sent to instance tableview swift无法识别的选择器发送到实例tableview swift
【发布时间】:2015-08-22 22:44:20
【问题描述】:

在我的cellFoRowAtIndexPath 中,我想在属于单元格的按钮上添加一个功能。

在我的cellFoRowAtIndexPath 中,我添加了此代码。

cell.acceptBtn.addTarget(self, action: "acceptRequest", forControlEvents: .TouchUpInside)

然后我这里有这个功能。

func acceptRequest(sender: UIButton) {
    println("hello"); 
}

当我运行项目并单击该单元格上的按钮时,我得到一个

由于发送到实例的未捕获异常“NSInvalidArgumentException”无法识别的选择器而终止应用程序

需要注意的是,我还有另一个按钮,我使用了相同的方式,称为declineRequest,它工作得非常好。

【问题讨论】:

标签: ios swift uitableview uibutton addtarget


【解决方案1】:

尝试以下方法:

cell.acceptBtn.addTarget(self, action: "acceptRequest:", forControlEvents: .TouchUpInside)

...注意它是"acceptRequest:" 而不是"acceptRequest"。后者意味着该函数没有参数。

【讨论】:

  • 谢谢!它解决了我的问题......多么愚蠢的错误,但你刚刚救了我会在 10 分钟内接受答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-16
  • 1970-01-01
  • 2018-04-24
相关资源
最近更新 更多