How to remove all view along with rootView from UINavigationController in iPhone

I have a UIView added to the main window with a controller. On a button click on this view, I want to load a UINavigationController that will wrap across multiple views by pushing them one by one on the stack. Now what I want to do is when the user reaches at the end of views, in the last view I have a done button. ON clik of this button I want to return to my first screen by unloading the NavigationController from memory.

What is the best way to do this since popToRootViewController takes you to the first screen of the UINavigationController which is my second screen.

+2


source to share


3 answers


Basically you want to remove the view of navigation controllers, so why can't you tell [navigationController.view removeFromSuperView]?



+1


source


One way to do this is to present the navigation controller as a modal controller and fire it when you're done:



// In the parent controller, when the navigation controller is about to appear:
UINavigationController* navController = [[UINavigationController alloc] init];
[self presentModalViewController:navController animated:YES];

// ... later, in the nav controller, when it done being used:
[self.parentViewController dismissModalViewControllerAnimated:YES];
[self autorelease];  // goodbye, cruel world (when the ar pool is drained)

      

0


source


Several ideas in order of desirability

  • make Controller # 1 the controller of the stack root view, then use popToRootViewController. Is there a good reason why you don't? Keep in mind that you can easily hide the navigation bar from any controller if that's what you're afraid of.

  • Add a method called "destroyNavigationStack" or something to main controller # 1 and refer to controller # 1 in the application delegate. In your Nth view controller, when "done" is deleted, get a reference to your application delegate (UApplication sharedApplication method) and send View Controller # 1 this "destroy" message. There is really no reason to even think about popping view controllers off the stack, since you want to get rid of the entire stack anyway.

  • Make ViewController # 1 a single and call destroyNavigationStack

0


source







All Articles