iOS開發手記 - iOS9.3 UINavigationController添加后不顯示storyboard中viewcontroller里的控件的解決方法


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

- (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中加載,我哪里沒注意到望大神告知


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM