我原先是这么作的,一般也是这么作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