最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】swift 3:Use ‘#selector’ instead of explicitly constructing a ‘Selector’

Swift crifan 2293浏览 0评论

代码:

        registerButton.addTarget(self, action: Selector("registerAction"), forControlEvents: UIControlEvents.TouchUpInside)

警告:

Use ‘#selector’ instead of explicitly constructing a ‘Selector’

改为:

//        registerButton.addTarget(self, action: Selector("registerAction"), forControlEvents: UIControlEvents.TouchUpInside)
        registerButton.addTarget(self, action: #selector(RegisterUsernameViewController.registerAction), forControlEvents: UIControlEvents.TouchUpInside)

即可。

还有类似的问题:

代码:

        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
        self.view.addGestureRecognizer(tap)

警告:

Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead

改为:

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.dismissKeyboard))

即可。

转载请注明:在路上 » 【已解决】swift 3:Use ‘#selector’ instead of explicitly constructing a ‘Selector’

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.282 seconds, using 22.06MB memory