iOS開發手記 - iOS9.3 UINavigationController添加後不顯示storyboard中viewcontroller裡的控制項的解決方案

來源:互聯網
上載者:User

標籤:

我原先是這麼做的,通常也是這麼做

- (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裡的控制項的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.