如何将附加参数传递给Swift 5中的selector @objc函数?
我想做的是:
@objc func sendLike(_ sender: Any, checkin: String) {
createLikeCheckin(checkin: checkin) // This is the URLSession function
}
// In tableView cellForRowAt
let checkin = self.userCheckins[indexPath.row]
cell.likeButton.addTarget(self, action: #selector(sendLike(_:, checkin: checkin.pk)), for: .touchUpInside)
因此,我可以传递签入对象的pk,然后在URLSession中使用。然而,我得到一个错误:在调用Insert '<#Any#>‘时参数#1缺少实参。
这导致我在选择fix后出现此错误:'#selector‘的参数没有引用'@objc’方法、属性或初始值设定项
发布于 2021-08-14 05:09:43
事实证明,我只是不擅长搜索
答案:Pass multiple parameters to addTarget
其他一些参考资料:Attach parameter to button.addTarget action in Swift
https://stackoverflow.com/questions/68779933
复制相似问题