0
votes

Inside UIViewController there is property:

 @property(nonatomic, readonly, retain) UINavigationController *navigationController

I am not really sure how is this property used... As the way I see it, if you have navigation controller named navController and type some code like this:

[navController pushViewController:nextController animated:YES];  

several things happen. First nextController is pushed on top of stack of navController. Second, navController retains nextController. Third, readonly property of nextController (navigationController) is initialized with navController. That way navController retains nextController, and nextController retains navController. This has as a consequence that if you release navController, it wouldn't be destroyed because it is retained by all UIViewControllers on its stack. The only way to release it is to pop all items from stack and then release it.

Is this how all of this functions, or am i missing something?

2

2 Answers

0
votes

Yes, you are missing that when nextController's dealloc method is invoked it will release its navigation controller. So when you release navController it will release all its pushed view controllers and they will release their navController. In other words, when you release a navigation controller (assuming release count is zero) , it will pop all view controllers pushed on it.

0
votes

if you already have a navigation controller and push a viewcontroller inside it then you can use this property to deal with the navigation controller .. for example

UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];

now you are have your vc inside the nav controller .. if you like to show another vc you can do it like this [vc.navigationController pushViewController:detailViewController animated:YES];

for the release you just need [vc release]; [navController realese];