我原先是這麼作的,一般也是這麼作windows
- (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裏的控件卻沒有顯示,一片空白app
事實證實不能這樣直接alloc firstVC,而是要從storyboard中加載,我改爲以下就好了:ide
- (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中加載,我哪裏沒注意到望大神告知blog