Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard Segue to Multiple Views?

I am setting up a bunch of view controllers in my storyboard and have a 'Next' button.

I need this to segue to two different view however my storyboard won't allow it. For example if certain criteria are met the next button will go to one view, if not, it will go to the other view.

Any help much appreciate achieving this.

Thanks.

like image 752
Josh Kahane Avatar asked Apr 09 '12 13:04

Josh Kahane


People also ask

How do you add a segue between two view controllers in a storyboard?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.


1 Answers

You need to create the two segues from your view controller, not from the button. In the storyboard, control-drag from the view controller to where you want the segue to go. Repeat for the other segue. Click on each segue and give them unique identifiers (for this demo I'll use "segue1" and "segue2").

Then, go to your ViewController that initiated the segues. You need to set an action up for your button.

-(void)buttonPressed:(UIButton*)sender{
   if(criteria met){
        [self performSegueWithIdentifier:@"segue1" sender:self];
     }
   else {
        [self performSegueWithIdentifier:@"segue2" sender:self];
   }
 }

Sender is self in this case because it is the view controller causing the segue, not the button directly. You will also need to implement prepareForSegue.

like image 95
Mike Z Avatar answered Sep 22 '22 14:09

Mike Z