【发布时间】:2017-08-01 08:24:33
【问题描述】:
我的收藏视图单元格中有一个自定义按钮。我只想将 indexPath 传递给它,但我得到了 “无法识别的选择器错误”
这是我的代码
cell.showMapButton.addTarget(self, action: #selector(testFunc(indexPath:)), for: .touchUpInside)
函数是
func testFunc(indexPath: IndexPath){
print("Testing indexPath \(indexPath)")
}
如果我删除 indexPath 参数,它可以正常工作并且函数会被调用,但我需要该参数,所以请帮助我解决这个问题。
【问题讨论】:
-
您可以使用委托模式或闭包。查看答案here
-
您不能在目标/操作模式中使用自定义参数。唯一受支持的参数是发送 UI 元素,即按钮。
标签: ios swift xcode swift3 selector