在ViewDidLoad上执行Segue [英] Perform Segue on ViewDidLoad

查看:75
本文介绍了在ViewDidLoad上执行Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 5中,我有一个带有模态视图控制器的故事板,如果用户是第一次在应用程序中,我想显示它,之后我想跳过这个视图控制器。

In iOS 5 I have a Storyboard with a modal view controller, that I would like to display if its the user's first time in the app, after that I would like to skip this view controller.

我设置了一个NSDefault键来处理这个问题,但当我检查是否设置了这个键然后使用performSegueWithIdentifier来启动segue时,没有任何反应。如果我把这个segue放在一个按钮后面它工作正常......

I set an NSDefault key to handle this but when I check to see if this is set and then use performSegueWithIdentifier to initiate the segue, nothing happens. If i put this segue behind a button it works fine...

推荐答案

我回答了一个类似的问题,开发人员想要展示一开始的登录屏幕。我为他准备了一些示例代码,可以在这里下载。解决这个问题的关键是如果你想显示这个新的视图控制器,在正确的时间调用东西,你会在示例中看到你必须使用这样的东西

I answered a similar question where the developer wanted to show a login screen at the start. I put together some sample code for him that can be downloaded here. The key to solving this problem is calling things at the right time if you want to display this new view controller, you will see in the example you have to use something like this

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:YES];
}

我还解释了segues和storyboards如何工作,你可以看到< a href =http://www.scott-sherwood.com/?p=219>这里

I also have an explanation of how segues and storyboards work that you can see here

这篇关于在ViewDidLoad上执行Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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