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
HomeScreenViewControllerwhich doesn’t exist on the navigation stack. You will have to get the existing instance and use it as an argument forpopToViewController:animated:method. You can do it by getting the view controller from theviewControllersarray which is a property onUINavigationController. They are indexed in order so if the view controller is at index 1 then get the view controller usingIf you want to go back to root view controller, use
popToRootViewControllerAnimated:instead.