最新消息:20210917 已从crifan.com换到crifan.org

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

Swift crifan 1762浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
101 queries in 0.188 seconds, using 23.29MB memory