来自app delegate的UIStoryboard加载 [英] UIStoryboard load from app delegate

查看:155
本文介绍了来自app delegate的UIStoryboard加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图以这种方式从app delegate .m加载UIStoryboard:

I am trying to load a UIStoryboard from the app delegate .m in this way:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    UIViewController *vc =[storybord instantiateInitialViewController];
    [self.window addSubview:vc.view];

    return YES;
}

这段代码有什么问题?任何想法?

What is the problem with this code?? any idea?

推荐答案

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
   UIViewController *vc =[storyboard instantiateInitialViewController];

   // Set root view controller and make windows visible
   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   self.window.rootViewController = vc;
   [self.window makeKeyAndVisible];

   return YES;
}

试试这个。我认为缺少设置根视图控制器并使窗口可见。

Try this. I think is missing set root view controller and make windows visible.

这篇关于来自app delegate的UIStoryboard加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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