ios在运行时更改故事板默认视图控制器 [英] ios change storyboard default view controller at run time

查看:86
本文介绍了ios在运行时更改故事板默认视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从故事板覆盖默认视图控制器以显示不同的控制器吗?这当然会发生在AppDelegate中。

It it possible to override the default view controller from a storyboard to show a different controller instead? This would all happen in the AppDelegate of course.

推荐答案

@ Martol1ni我想用你的答案,但我也想留下来远离不必要的故事板混乱,所以我稍微调整了你的代码。但是我确实给了你一个+1的鼓舞人心的答案。

@Martol1ni I wanted to use your answer, but I also wanted to stay away from unnecessary storyboard clutter so I tweaked your code a bit. However I did give you a +1 for your inspiring answer.

我将以下所有内容都放在默认控制器上。

I put all of the following on the default controller.

- (void)gotoScreen:(NSString *)theScreen
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen];
    [app.window setRootViewController:screen];
}

然后在逻辑发生的地方我会根据需要调用以下内容。

And then where the logic happens I'll call the following as needed.

if(myBool == YES) {
    [self gotoScreen:@"theIdentifier"];
}

这篇关于ios在运行时更改故事板默认视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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