The best way to move back and forth is to pop and display views from the navigation controller stack.
To return to one view, use the code below. This will ensure a smooth transition between views.
UINavigationController *navigationController = self.navigationController; [navigationController popViewControllerAnimated:YES];
To go back to the two views, do as shown below
UINavigationController *navigationController = self.navigationController; [navigationController popViewControllerAnimated:NO]; [navigationController popViewControllerAnimated:YES];
If you do not return to the expected view, execute the code below before any of the views appear ...
UINavigationController *navigationController = self.navigationController; NSLog(@"Views in hierarchy: %@", [navigationController viewControllers]);
You should see an array like the one below that will help you check the stack, as expected.
Views in hierarchy: ( "<Main_ViewController: 0x1769a3b0>", "<First_ViewController: 0x176a5610>", "<Second_ViewController: 0x176af180>"
source share