我想張貼通知如下:NSNotificationCenter觀察者不起作用
NSNotificationCenter .defaultCenter() .postNotificationName("name", object: nil)
從viewControllerA
的函數內然後在ViewControllerB在viewDidLoad
NSNotificationCenter.defaultCenter().addObserver(self, selector: "doSomething:", name:"name", object: nil)
但從來沒有叫過doSomething:
!
有什麼想法?
您需要先'addObserver',然後'postNotificationName'。 – Leo
@Leo對不起,我不明白。我在哪裏應該addObserver(在我的ViewControllerA?,然後在相同的ViewControllerA postNotification? –
我的意思是你發佈通知時,應該已經有一個觀察者在內存中 – Leo