Diego Peng
Diego Peng

Reputation: 79

disabled the storyboard jump

i have create a project about storyboard, there are two view controllers on storyboard named 'loginViewController','BViewController', a login button on loginViewController, i have set login button triggered segues action is BViewController.

in the event of login button, if login successful i want jump to BViewController else disabled the jump, but looks like always jump to BViewController, how can i let it does not jump?

if (loginResult)
{
    [self.navigationController popViewControllerAnimated:YES];
}
else
{

}

Upvotes: 0

Views: 22

Answers (2)

Duncan C
Duncan C

Reputation: 131426

To expand a little on @PeterLendvay 's answer: If you attach a segue to a button, the segue always triggers when the user clicks the button (assuming the button is enabled.) If you want to add logic that decides what to do, don't link a segue directly to the button.

Instead, make a segue between the view controllers. Name that segue with a unique identifier.

Then attach an IBAction to the button. Now you can run code when the user clicks the button. In that code, decide if you should trigger the segue or not. If you do want to trigger the segue, invoke the performSegueWithIdentifier method.

You can also use this approach to have a button decide between several different segues.

Upvotes: 0

Peter Lendvay
Peter Lendvay

Reputation: 655

You should set the segue between the UIViewControllers and set a separate IBAction on the button. In the IBAction use this:

 if (loginResult)
{
   [self performSegueWithIdentifier:@"jumpToBViewController" sender:self];
}

Dont forget to set the identifier of the segue to "jumpToBViewController" on the storyboard.

Upvotes: 1

Related Questions