Akyri
Akyri

Reputation: 35

Dismissing a modal view controller and THEN performing a segue

I'm in the early stages of creating an application and have run into a problem. Essentially, I'm using the Parse SDK to signup/login to the backend. The loginViewController is the initial view controller. Upon tapping 'signup', the signupViewController is presented modally. Once the user is logged in, I want the tab bar controller that contains the rest of the app to be presented modally.

Here's the storyboard so far:

Storyboard Image

Now when the user logs in, I perform the manual segue between login and signup. That works perfectly. My question is, what would be the best practice for doing the same thing for the signup view controller? Should I create ANOTHER manual segue between it and the tab bar controller, or is there someway I can dismiss it first, and then perform the segue from the login view controller.

I have looked for an answer in Apple's documentation, and on a few other sites, without any success. Any help at all on the matter would be appreciated greatly!

Upvotes: 2

Views: 1190

Answers (2)

Gary Foster
Gary Foster

Reputation: 171

You could have the loginViewController be "aware" of the state of things and handle the routing. For example:

  • add a boolean property in a global scope, perhaps in the AppDelegate, named like signedUp, default to false
  • user logs in, sign up vc is opened
  • user signs up, on success, set the signedUp prop to true
  • sign up vc is popped, user is back on login vc
  • in the loginvc viewDidAppear check if signedUp = true and segue to the tab bar controller

Another option would be to combine the login and sign viewcontrollers into one and show/hide the controls on the form depending on the mode, which will then simplify your flow having just one vc to deal with.

Upvotes: 1

heximal
heximal

Reputation: 10517

There is an option I can suggest. You can instantiate view controller using the approach

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
id controllerToPush = [storyboard instantiateViewControllerWithIdentifier:@"desiredViewController"];

(MainStoryboard_iPhone and desiredViewController are specified in interface builder). Then push this controller. For instance, if you're using Navigation controller pattern:

[self.navigationController setViewControllers:@[controllerToPush] animated:YES];

Upvotes: 0

Related Questions