2

I want to remove all the viewcontrollers from UINavigationController. So I am using this code.

for (UIViewController* controller in navigationController.viewControllers) {
[controller removeFromParentViewController];
}

After that I create an new viewController and push it.

 UIViewController* newVC=[[UIViewController alloc] init]; 
 [navigationController pushViewController:newVC animated:YES];

Issue is all the viewcontrollers popout perfectly and adding newVC but on pushing newVC the navigationbar is getting a back button and title of newVC. On clicking back button it animates to the navigationbar of oldVC with title of oldVC that I have already removed in above loop;

NaXir
  • 2,373
  • 2
  • 24
  • 31

2 Answers2

0

removeFromParentViewController is a UIViewController method, so it's normal it has nothing to do with UINavigationBar

In the case of a UINavigationController the popViewControllerAnimated: method handles the removeFromParentViewControllerpart for you, along with navigation bar.

you can directly update the whole array of viewControllersof UINavigationController, calling `setViewControllers:animated:

see Replacing rootView in navigationController

Community
  • 1
  • 1
Vinzzz
  • 11,746
  • 5
  • 36
  • 42
0

[navigationController setViewControllers:[NSArray arrayWithObject:newVC]];

Donald
  • 321
  • 1
  • 2
  • 10