加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

语法“Selector”Swift 2.2

发布时间:2020-12-14 05:28:21 所属栏目:百科 来源:网络整理
导读:我正在尝试修复我的NSNotificationCenter并且它无法正常工作 消息: 'Use of string literal for Objective-C selectors is deprecated; use '#selector' instead'. 这条线: NSNotificationCenter.defaultCenter().addObserver(self,Selector :#selector(Ga
我正在尝试修复我的NSNotificationCenter并且它无法正常工作

消息:

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

这条线:

NSNotificationCenter.defaultCenter().addObserver(self,Selector :#selector(GameViewController.goBack)(GameViewController.goBack),object: nil)
        self.dismissViewControllerAnimated(true,completion: {
        });
        }
@ Eendje的回答是不正确的第一条评论.

我认为这是更好的答案.

NSNotificationCenter.defaultCenter().addObserver(self,#selector(self.goBack),name: "your notification name",object: nil)

如果某些操作有目标,则应该显示为#selector(target.method)或#selector(target.method(_ :))

这是另一个例子

UIGestureRecognizer(target: target action:#selector(target.handleGesture(_:))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读