Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pop to initial view controller

I am currently writing an app that uses embedded navigationControllers. I need to pop to the initial view of the first view controller from within the embedded one.

This line of code just returns me to the initial view of the embedded navigationController:

[self.navigationController popToRootViewControllerAnimated:YES];

Any ideas?

like image 909
user3250926 Avatar asked Jun 01 '26 15:06

user3250926


1 Answers

You could do some recursive function like this. Name this whatever you would like or make it a category for convenience.

- (void)recursivePop:(UIViewController *)viewController
{
   if (viewController.navigationController)
   {
       [viewController.navigationController popToRootViewControllerAnimated:YES];
       [self recursivePop:viewController.navigationController];
   }
}

Then in the view controller you want to invoke this with call it like this.

[self recursivePop:self];
like image 166
GregP Avatar answered Jun 03 '26 03:06

GregP