我正在尝试修复我的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的回答是不正确的第一条评论.
原文链接:https://www.f2er.com/swift/319298.html我认为这是更好的答案.
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(_:))