语法“Selector”Swift 2.2

栏目: Swift · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/36147831/syntax-selector-swift-2-2

我正在尝试修复我的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(_:))

翻译自:https://stackoverflow.com/questions/36147831/syntax-selector-swift-2-2


以上所述就是小编给大家介绍的《语法“Selector”Swift 2.2》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Text Processing in Python

Text Processing in Python

David Mertz / Addison-Wesley Professional / 2003-6-12 / USD 54.99

Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing som......一起来看看 《Text Processing in Python》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具