我想张贴通知如下: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