故事板瞄准多个视图? [英] Storyboard Segue to Multiple Views?

查看:101
本文介绍了故事板瞄准多个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的故事板中设置了一堆视图控制器,并有一个下一步按钮。

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.

谢谢。

推荐答案

您需要创建两个segue查看控制器,而不是按钮。在故事板中,控制 - 从视图控制器拖动到您想要segue的位置。重复另一个segue。单击每个segue并为它们指定唯一标识符(对于此演示,我将使用segue1和segue2)。

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").

然后,转到启动了它的ViewController塞格斯。你需要为你的按钮设置一个动作。

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];
   }
 }

发送者在这种情况下是自我,因为它是视图控制器导致segue,而不是直接按钮。您还需要实现prepareForSegue。

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.

这篇关于故事板瞄准多个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆