我按如下方式设置了一个观察者,其中包括以下logYes()功能:
class SplashPageVC: UIViewController {
func logYes() {
println("Yes");
}
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "logYes:", name: "userValid", object: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我已经将以下IBAction连接到一个按钮:
class LoginVC: UIViewController {
@IBAction func loginSubmitted(sender : AnyObject) {
NSNotificationCenter.defaultCenter().postNotificationName("userValid", object: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
点击按钮时出现以下错误:
[_TtC13Explorer12SplashPageVC self.logYes:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
我尝试了一堆不同的选择器,没有运气:
logYes
logYes:
logYes()
logYes():
Run Code Online (Sandbox Code Playgroud)
我没有想法.任何见解?tyvm :)
参考文献:
在postNotificationName中没有发送
NSNotification :在Swift 中的swift委托中称为NSNotificationCenter addObserver
?
Tim*_*Tim 33
我认为你的原始选择器(logYes:)是正确的 - 这是你应该重写的功能.通知观察器函数接收发布的通知作为参数,因此您应该写:
func logYes(note: NSNotification) {
println("Yes")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7059 次 |
| 最近记录: |