Why would adding a delegate to a UINavigationController crash my app?
I'm working on an iPhone application. I'm using Storyboard.
I wanted to have one object attached to the NavController to handle the visibility of the button bar at the bottom of windows that display table views.
I created my own UINavigationDelegate; MyNavigationControllerDelegate.
I have created an NSObject in UIBuilder and changed its class MyNavigationControllerDelegate. And then attached it as the delegate of the UINavigationController.
For some reason MyNavigationControllerDelegate is getting deallocated. I would have thought that being the delegate would be enough to keep a reference to it and prevent deallocation, but that seems not to be the case.
Any suggestions as to how to prevent it from being deallocated? And do I have to reset it as the delegate each time a view is loaded?
The delegate property of UINavigationController is declared as assign rather than retain or strong (see here). Delegates are typically declared either weak or assign, which means assigning the property will not cause the UINavigationController to increase the reference count on your delegate, and you need another object to hold a strong reference to it (perhaps your RootViewController).