0

We are making a school choice system showing a list of schools. When I press the school it goes to the next screen. WHen I reached the next screen and I want to go back to the school selection screen, pressing the navbar "back <" item it goes to the first screen instead of going to the school selection screen.

So the question is short is.

How can I make the navbar BACK button forget my option chosen before and go back to the school select screen.

Thanks in advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579

4 Answers4

0

Use popViewController which will take you back by exactly one screen.

TorukMakto
  • 2,066
  • 2
  • 24
  • 38
0

You have 3 types of pops :

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

If you have more view controllers before the school selection you can go back two view controllers:

NSArray* viewControllers = self.navigationController.viewControllers;

[self.navigationController popToViewController:[viewControllers[viewControllers.count-1]] animated:YES];

If your school selection is the root then you can jump straight to your rootViewController:

[self popToRootViewControllerAnimated: YES]
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
  • The problem is, the navbar back button does not use the ViewDidLoad, thats our main problem. Somehow we can't use the pops since the viewcontroller does not contain the navbar items. We use a navigation controller. Any plans or am I making a mistake here? – user3035721 Nov 26 '13 at 09:53
  • When you do "Pop" you are not loading the views. They were already loaded. The only methods that will be called is the viewWillAppear and viewDidAppear. – Tiago Almeida Nov 26 '13 at 10:04
  • Okay so I can simple use this POP method in my viewcontroller class? – user3035721 Nov 26 '13 at 10:08
  • The back button does a pop automatically. However, it pops to your last ViewController. If you want to pop to a different viewcontroller you can use one of the methods above. However, you have to override your back button ( http://stackoverflow.com/questions/5085452/override-back-button-in-navigation-stack ) – Tiago Almeida Nov 26 '13 at 10:14
  • It has to go to my last viewcontroller so thats okay. – user3035721 Nov 26 '13 at 10:18
  • I assume I have to put the pop in my UINavigationController.h But where is the function for the navbar BACK button – user3035721 Nov 26 '13 at 10:26
0
`[self.navigationController popToViewController:SchoolSelectionViewController];` //replace SchoolSelectionViewController with the name of School selection screen
Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
0

[self.navigationController popViewControllerAnimated:YES];