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?

Answers


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).


Need Your Help

How to know if device has Navigation Bar

android genymotion navigationbar

How can I know programmatically if a device has a navigation bar and if it has it how can i get the size (width and height).

Google Forms - get multiple choice response's index

google-apps-script google-sheets google-form

I have a Google Form with several multiple choice questions which have textual answers.