【问题标题】:Unrecognized selector sent to instance - Swift无法识别的选择器发送到实例 - Swift
【发布时间】:2015-08-14 09:13:14
【问题描述】:

这个问题已经在 SO 上被问过几次了,但解决方案似乎总是在action 字符串的末尾添加:,或者添加一个发件人参数,如UIButtonAnyObject,但这不适用于我。

这是我的代码:(在cellForRowAtIndexPath 函数内)

    let mapsbut = cell.viewWithTag(912) as! UIButton

    mapsbut.addTarget(self, action: "mapsHit:", forControlEvents: UIControlEvents.TouchUpInside)

    func mapsHit(sender: UIButton!){

        passBuild = buildings[indexPath.row]
        performSegueWithIdentifier("mapSegue2", sender: self)

    }
    return cell

有什么想法吗?

【问题讨论】:

    标签: ios swift uibutton


    【解决方案1】:

    尝试将 mapsHit 函数移出 cellForRowAtIndexPath: 函数,使其成为全局(在视图控制器上下文中)而不是 cellForRowAtIndexPath 方法中的嵌套函数。

    【讨论】:

    • 这可能有效,但我需要使用函数中单元格中的值,所以这种方法不适合我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多