0

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?

Earl Grey
  • 7,426
  • 6
  • 39
  • 59

1 Answers1

0

[This is kind of an oblique answer, apologies.]

I'm guessing you are dissatisfied with the standard Apple way of doing things, and are attempting to find something better. If that's the case, you're not alone.

If you are not aware of these, you might want to check out the "Model View ViewModel" concept, ReactiveCocoa, and ReactiveViewModel. ReactiveCocoa can be a steep conceptual cliff to climb, but if you are adventuring already, it's worth checking out.

Clay Bridges
  • 11,602
  • 10
  • 68
  • 118