简体   繁体   English

使用未解决的标识符swift 3

[英]Use of unresolved identifier swift 3

So I have an old app that needs to be updated and this was the original code that worked: 所以我有一个旧的应用程序需要更新,这是起作用的原始代码:

myBtn.addTarget(nil, action:("addNewObject"), for:.touchUpInside)

"addNewObject" is a function common in several different classes of which an instance of myBtn will exist. “ addNewObject”是存在于myBtn实例的几个不同类中的通用函数。 However after trying to update the code to Swift 3 as below, I now get the "Use of unresolved identifier" error. 但是,在尝试将代码更新为如下所示的Swift 3之后,我现在收到“使用未解决的标识符”错误。

myBtn.addTarget(nil, action:(#selector(addNewObject)), for:.touchUpInside)

You should not use nil , use self 您不应该使用nil ,而要使用self

myBtn.addTarget(self, action: #selector(addNewObject), for: .touchUpInside)

Implement addNewObject method like this, 像这样实现addNewObject方法,

@IBAction func addNewObject() {
    //Your code goes here
}

The target can not be nil. 目标不能为nil。 Change "nil" to "self". 将“无”更改为“自我”。

myBtn.addTarget(self, action: (#selector(addNewObject)), for: .touchUpInside)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM