I have to pop to HomeScreenViewController from current view controller after clicking on custom back button, which is added on main window as a light box. I used following code :
HomeScreenViewController *homeController = [[HomeScreenViewController alloc]
initWithNibName:@"HomeScreenViewController" bundle:nil];
[self.navigationController popToViewController:homeController animated:YES];
[homeController release];
I got crashing with exception : Tried to pop to a view controller that doesn't exist.
How can it be implemented? What changes are required for implementing it?
Clearly you are creating a new instance of HomeScreenViewController
which doesn't exist on the navigation stack. You will have to get the existing instance and use it as an argument for popToViewController:animated:
method. You can do it by getting the view controller from the viewControllers
array which is a property on UINavigationController
. They are indexed in order so if the view controller is at index 1 then get the view controller using
UIViewController * viewController = [self.navigationController.viewControllers objectAtIndex:1];
[self.navigationController popToViewController:viewController animated:YES];
If you want to go back to root view controller, use popToRootViewControllerAnimated:
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With