2
votes

This is my first time using story board and I've set up like 5 view controllers with UINavigationController with buttons that push to the next view controller..

So I start on VC1 and push to VC2, then click and button and push to VC3, then click a button and push to VC4, and so on... on the last screen (VC5) I have a "home" button that the user can click to go back to the home screen (VC1), I've set it up so it pushes to VC1, the problem is when the user clicks that they are taken to the homescreen but then there is a back button on the navigation bar and they can go back to the last screen? After they click home they should not be able to return to previous screens without navigating through to them like they had the first time!

How can I accomplish this? Thanks! I'm used to working with xib and programmatically controlling the UINavigationControllers so this StoryBoard stuff is very new to me haha!

2
If you don't want the back button, you don't wanna do a push, you can either pop all the way back to the controller you want, or just load it up the old fashioned way.Kevin DiTraglia
@KevinDiTraglia How do I "pop" in the storyboard file? Or does that have to be done with code? If so, what's the code I can add to my viewController5.m ?Albert Renshaw
Both would be through code behind. Look into popViewControllerAnimated on the navigation controllerKevin DiTraglia
@KevinDiTraglia I removed the "push" from that button in the storyboard then in my .m file added [self.navigationController popViewControllerAnimated:YES]; and it only took me back 1 ViewController from VC5 to VC4? How do I "pop" to a specific VC like VC1?Albert Renshaw
@KevinDiTraglia Got it! NSArray *array = [self.navigationController viewControllers]; [self.navigationController popToViewController:[array objectAtIndex:0] animated:YES];Albert Renshaw

2 Answers

8
votes

It sounds like you want an unwind segue. On the VC1 .m file add the following blank method:

 - (IBAction)unwindToVC1:(UIStoryboardSegue*)sender
 {
 }

Then in your storyboard on VC5 Ctrl-drag from your home button to the green Exit button at the bottom of your view controller. Choose the unwindToMainMenu option and it should now go back to the VC1 when pressed and no longer have the back button as it has popped all the view controllers.

4
votes

I think the method you're looking for is popToRootViewControllerAnimated:

[self.navigationController popToRootViewControllerAnimated:YES];