iOS: Make segue wait for login success

mtmurdock picture mtmurdock · Nov 19, 2011 · Viewed 7.6k times · Source

I am designing an iOS app using XCode 4.2's storyboard feature. The app has a login screen that takes a username and password and has a button to log in. Pushing the login button triggers a push seque to another view controller. However, I want the seque to wait until the login comes back successful before proceeding to the next view controller.

I know about prepareForSegue:sender: but heres my issue: the login call is asynchronous. I therefore cannot perform the login there.

Is there someway around this? Can I create a seque in the storyboard that is only triggered when I want it to be (as opposed to when a button is clicked)?

Answer

mtmurdock picture mtmurdock · Nov 21, 2011

Ok, I have figured it out. I had defined a segue from a UIButton to the next UIViewController. As defined in this manner, there is no way to conditionally execute the segue.

Instead of putting the segue on the button, I made a segue from the first UIViewController to the other UIViewController. This defines the segue, but associates no action with it. From there I can simply call performSegueWithIdentifier:sender: when I want that segue to execute (in my case being when the async task is complete).

The main advantage of this for me is that IB maintains its structure.

Big thanks to @cli_hlt for pointing me in the right direction (+1).