I have 3 viewControllers, From the first i go to the second, and from the second to the third.
I want to go from the third view controller back to the first.
One solution I found is to create a custom button and replace the back button, this way I perform my own selector and go back to the firstVC. But the button I created doesnt look like the back button.
So one solution I thought about is:
Once I enter the third view controller, alter the viewControllers arrays in the navigationController removing the second view controller. This way it would go back to the first without changing the back button.
Is this possible? can I change the UINavigationController stack at will?
Thanks in advance
You can, there is a special method for that - [UINavigationController setViewControllers:animated:].
You can try to remove the second view controller from the stack and check it. Shouldn't be a problem.
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[array removeObjectAtIndex:1];
self.navigationController.viewControllers = array;
Or just use
[self.navigationController setViewControllers:array animated:NO];
But this is not a recommended approach as the users might get confused. So be careful when you are doing it this way.
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