I am dispatching notification from my facade class which hides the complexity of the model from my viewcontrollers. Now, I have a simple tab barcontroller with a navigation controller on the first tab. So far so good, a very typical design. Now this navigation controller has two view controllers on its stack. The root MainViewController with a tableview and the DetailViewController with a few views.
The mainViewController is an observer for 4 notifications in viewDidLoad. I have four handling methods for each notification. I unregister for these notifications in dealloc.
The problem is when i select a tableViewCell in mainViewController and the detailViewController is pushed onto stack, and then when I go back to the main view controller pushing the back button, at that very moment the mainViewController is removed as an observer from the Notifications Dispatch table, effectively it is like it would unregister for those notifications.
Why is this happening? Is it by design or am I missing something?
The instance of the mainViewController is not destroyed, it still exists on the navigation stack, dealloc is not called, so why would it deregister?
A quick and dirty solution is put the registration to those notifications to viewWillAppear but I don't like it as this registration code is run unnecessarily many times (viewDidLoad should suffice.)
Any help?