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

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

问题描述

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

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

我还对转场和故事板的工作原理进行了说明,您可以在此处

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

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

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