I am trying to use a custom back button on my View Controller in Objective-C to pop the current view controller so that i can go back to previous controller. All the controllers are just view controllers and are not modally presented. How do I programmatically pop the current view controller (non modal) and go back to previous one?
this will pop the top controller from navigation controller stack!
[self.navigationController popViewControllerAnimated:YES];
and if you are not aware of UINavigationController and its uses then follow this link
http://www.idev101.com/code/User_Interface/UINavigationController/
You need to use a UINavigationController
.
This maintains a stack of your view controllers. You can modify your view stack by calling pushViewController:animated
and popViewController:animated
.
Initialize your instance of UINavigationController
with a rootViewController (your first view controller), and then present your UINavigationController in some way, then all you need is to play around with your UINavigationController
instance.
if you are pushing the view controller use:
[self.navigationController popViewControllerAnimated:NO];
else if you are using a modal transition use:
[self dismissViewControllerAnimated:YES completion:^{
//Stuff after dismissing
}];
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