In this Navigation Controller App, I have a button in the TAN ViewController that when clicked on posts an NSNotification.
-Both the Blue (Root) ViewController and the Green ViewController are listening to this same notification
-The Blue ViewController successfully responds to the notification's arrival
-The Green ViewController DOES NOT respond to it successfully. It doesn't even see it arriving (even though I'm using the exact same code as the Blue ViewController's code to register to listen for this Notification.)
-In both cases I'm registering to listen for the notification in viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
// Set Up Listening to Notification:
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(self, selector: "handleNotification:", name:"User Specs Notification", object: nil)
}
I also make sure to visit the GREEN ViewController - which automatically triggers its viewDidLoad
and executes the Notification listening code - before I ever go to the TAN ViewController and post the Notification from there. But again, when I go back to the Blue/Root ViewController, I see that it has responded correctly to the Notification's arrival, but when I then go to the Green ViewController - nothing has changed.
Any ideas what's going on?
Should I be registering to listen for the Notification someplace other than viewDidLoad
? If so, where? And why is it still working for the Blue/Root ViewController - where I am registering in viewDidLoad
- but not in the Green ViewController? Where's the logic in this?
The green view controller is deallocated when you go back to blue VC. So it's not there to receive the notification.