Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

ios - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...