我原先是這么做的,通常也是這么做
- (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中加載,我哪里沒注意到望大神告知
