1

I'm trying to create an app using storyboard which has 4 scenes:

  • ChooseLoginMethod
  • EnterLoginData
  • SuccessfulLogin
  • MainScene.

What I'm doing right now is the following: I have an UINavigationController which has ChooseLoginMethod as its root view. ChooseLoginMethod has several buttons (for different login methods) which are push segues to EnterLoginData. EnterLoginData has a push segue to SuccesfullLogin and SucessfullLogin has a push segue to MainScene.

The problem is that SuccessfulLogin and MainScene display the back button on the top bar, which makes no sense for the application.

I've tried:

  • Hidding the top bar on these two Views. Not successful.
  • Changing the segue to modal. Seems to work, but doesn't feel like the right thing to do.

So what I would like to do is create a segue which breaks the chain of Views which are on the UINavigationController's stack. Is there a proper way to do this in storyboard?

-- edit --

Maybe what I should do is replace the root view ( Set root view for UINavigationController ). This may work, but seems like a programming work-around for something that should be possible to be done in storyboard. Or maybe it is just me not getting the "iOS way of doing stuff".

Community
  • 1
  • 1
JoaoHornburg
  • 917
  • 1
  • 11
  • 22
  • 2 things: 1) How is hiding the top bar not working? What are you trying to do to achieve that result, and what is happening? 2) If you want the navigation bar to continue to appear, you can simply hide the back button in those views instead of the whole navigation bar – Dan F Dec 05 '12 at 16:33
  • You could use the login procedure navigation controller in a modal view and then remove the modal view in front of your main scene as soon as you are logged in. – nooitaf Dec 05 '12 at 16:37
  • @DanF setting top bar to "none" a the attributes panel in XCode. – JoaoHornburg Dec 05 '12 at 16:51
  • You need to hide the navBar from the viewWillAppear Jaoa as zapslock suggested. This will prevent the user from accessing the rootViewController while also retaining a reference to the view (if you need it, for instance, if the user is logged out you can pop back to the rootView to login again) – Mark McCorkle Dec 05 '12 at 17:12

2 Answers2

2

You had to use setNavigationBarHidden before the viewcontroller appears on the screen, like in viewWillAppear.

But then you can't go back from "MainScene" to the "RootController". So you should do something like popToRootViewController after "SuccessfulLogin" and then pop "MainScene".

xapslock
  • 1,119
  • 8
  • 21
  • Good suggestion to pop to the root controller so that the other views aren't sitting in memory, but inaccessible on the stack – Dan F Dec 05 '12 at 16:53
1

I think it's usually best to have your main scene be the root view controller. From its viewDidAppear method, you can present your ChooseLoginMethod controller modally, and from there do modal transitions to your other login controllers. When you get to the end, and you want to go back to the main scene just dismiss the modals from the root view controller -- this will dismiss the first one, and any that were presented from it:

[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
rdelmar
  • 103,982
  • 12
  • 207
  • 218