This is the simple code I am calling to go back to rootViewController
of UINavigationController
:
-(void)viewWillDisappear:(BOOL)animated
{
[self.navigationController popToRootViewControllerAnimated:YES];
[super viewWillDisappear:animated];
}
But the back navigation occurs one by one.
Say I have 3 viewControllers - A, B, C.
A -> B -> C
What I want on back of C is :
C -> A
But on using popToRootViewControllerAnimated, this is how back navigation appears :
C -> B -> A
Try to use
instead of
wrap this in a category and add your logic to make it more modular. You can jump to any view controller.
Another way of doing is that swizzling
popToRootViewControllerAnimated
which I think you should definitely avoid since this is a general method used heavily app-wise. You can modify it's actual behavior with your swizzled behavior.See http://nshipster.com/method-swizzling/ for swizzling.