How to reject a PushViewController?

I have 10 viewControllers in my application. I clicked all these viewControllers using the pushViewController method for the NavigationController, by pressing the NEXT button of each viewController click.

I used the code for this:

[self.navigationController pushViewController:someView animated:YES];

Now I want to return to rootViewController from the 10th child (viewController).

How can i do this?

Please help me..

Thank.

+5
source share
6 answers

try to use.

[self.navigationController popToRootViewControllerAnimated:YES];
+16
source

Use this code:

 [self.navigationController popToRootViewControllerAnimated:YES];
+10
source

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Use the desired index instead of 1 here

[self.navigationController popViewControllerAnimated:YES]
+9

[self.navigationController popViewControllerAnimated:YES] .

+1
 NSInteger index = 0;
 for (UIViewController *view in self.navigationController.viewControllers) {
 if([view.nibName isEqualToString:@"RootViewController"])//put any `XIB name` where u want to navigate 
    break;
index = index + 1;
 }
 [[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES]; 
+1
source

To return to the previous screen (the last element of the view controller stack), click the view controller:

[self.navigationController popViewControllerAnimated:YES];
+1
source

All Articles