I am using a UITabBarController
, and my 3rd tab observes an array on a singleton data store (implemented in viewDidLoad
).
Currently if I just log out (and change root view controller from App Delegate
), the app will crash when dealloc
is called on that 3rd tab with the message "cannot remove observer for the key path "X" because it is not registered as an observer.
Using breakpoints, I see that viewDidLoad
is never called on this 3rd tab, however dealloc is being called when I sign out. What is going on? I assume the UITabBarController
is holding a reference to the 3rd tab when I enter the storyboard, but does not "load" that tab. Yet iOS calls dealloc on it when I release the tab bar controller.
Should I use a boolean to track viewDidLoad
execution, or try to remove the observer with a @try
statement? Is there an overall better design for this?