0
其實我是新來的,我在這裏卡住了,任何人都可以解決這個問題。 actOnSpecialNotification Func鍵不ViewController.swiftNsNotificationCenter無法正常工作
呼籲fireNotification在ViewController.swift
func fireNotification() -> Void {
NotificationCenter.default.addObserver(self, selector:
#selector(vikas.updateNotificationSentLabel), name:
NSNotification.Name(rawValue: mySpecialNotificationKey), object: nil)
}
func updateNotificationSentLabel() {
print("sent")
}
在SecondVC.swift
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector:
#selector(ViewController.actOnSpecialNotification), name:
NSNotification.Name(rawValue: mySpecialNotificationKey), object: nil)
}
func actOnSpecialNotification() {
print("listen")
}
你'fireNotification()'不火任何上述方法的通知,只有一個觀察者。 – Moritz