Reputation: 881
I have 10 viewControllers in my app. I have pushed all these viewControllers using pushViewController method of NavigationController on NEXT button clicked of each viewController.
I have used code for that as ;
[self.navigationController pushViewController:someView animated:YES];
Now i want to jump back to the rootViewController from the 10th child(viewController).
How can i do this ?
Please help me..
Thanks.
Upvotes: 6
Views: 14041
Reputation: 1068
FOR SWIFT 4
self.navigationController?.popToRootViewController(animated: true)
Upvotes: -1
Reputation: 3908
you can use
[self.navigationController popViewControllerAnimated:YES]
for particular view ..
Upvotes: 1
Reputation: 2253
try to use ..
[self.navigationController popToRootViewControllerAnimated:YES];
Upvotes: 17
Reputation: 541
Try this
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Use the desired index instead of 1 here
for just go back to last screen use this
[self.navigationController popViewControllerAnimated:YES]
Upvotes: 10
Reputation:
To go back to the previous screen (last element of the view controller stack), pop the view controller:
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 1
Reputation: 1694
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];
Upvotes: 1
Reputation: 17186
Use this code:
[self.navigationController popToRootViewControllerAnimated:YES];
Upvotes: 11