最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

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

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
66 queries in 0.093 seconds, using 18.58MB memory