码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发手记 - iOS9.3 UINavigationController添加后不显示storyboard中viewcontroller里的控件的解决方法

时间:2016-08-05 00:37:50      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

我原先是这么做的,通常也是这么做

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    ViewController *firstVC = [[ViewController alloc] init];
    UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:firstVC];
    self.window.rootViewController = naviController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
 

 然而运行后,UINavigationController的确作为windows的根视图显示了,但是firstVC里的控件却没有显示,一片空白

事实证明不能这样直接alloc firstVC,而是要从storyboard中加载,我改成如下就行了:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_" bundle:nil];
    ViewController *firstVC = [storyBoard instantiateViewControllerWithIdentifier:@"MainView"];
    UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:firstVC];
    self.window.rootViewController = naviController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

我查看过很多代码例子都是像前者一样直接alloc加载就可以,但是我这里却不行,一定要这样从storyboard中加载,我哪里没注意到望大神告知

iOS开发手记 - iOS9.3 UINavigationController添加后不显示storyboard中viewcontroller里的控件的解决方法

标签:

原文地址:http://www.cnblogs.com/dcai/p/5738851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!