Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pop current view controller (non modal) and go back to previous one? [closed]

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?

like image 653
Pra Do Avatar asked Jun 30 '14 07:06

Pra Do


3 Answers

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/

like image 125
Retro Avatar answered Sep 22 '22 14:09

Retro


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.

like image 22
Vinod Vishwanath Avatar answered Sep 21 '22 14:09

Vinod Vishwanath


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
        }];
like image 25
Bogdan Somlea Avatar answered Sep 21 '22 14:09

Bogdan Somlea