【问题标题】:Swift 5 | How to pass additional parameters to selector @objc斯威夫特 5 |如何将附加参数传递给选择器@objc
【发布时间】:2021-08-14 02:47:44
【问题描述】:

如何在 Swift 5 中将附加参数传递给选择器 @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 ', '

中的参数 #1 缺少参数

选择修复后导致我出现此错误:“#selector”的参数不引用“@objc”方法、属性或初始化程序

【问题讨论】:

标签: uibutton swift5


【解决方案1】:

原来我的搜索能力很差

回答:Pass multiple parameters to addTarget

其他一些参考:Attach parameter to button.addTarget action in Swift

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 2018-10-10
    • 2017-07-22
    • 2017-03-24
    相关资源
    最近更新 更多