Application windows are expected to have a root view controller at the end of application launch
源代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//-------------------------------------------------------------------------------------
//创建基准的Controller对象
mainViewController = [ [ MainViewController alloc ] init ];
rootController = [ [ UINavigationController alloc ]
initWithRootViewController: mainViewController ];
// 将母体Controller的view 追加到Window中
[ self.window addSubview: rootController.view ];
//-------------------------------------------------------------------------------------
return YES;
}
每次运行都出现
修改代码:
添加
self.window.rootViewController = rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//-------------------------------------------------------------------------------------
//创建基准的Controller对象
mainViewController = [ [ MainViewController alloc ] init ];
rootController = [ [ UINavigationController alloc ]
initWithRootViewController: mainViewController ];
self.window.rootViewController = rootController;
// 将母体Controller的view 追加到Window中
[ self.window addSubview: rootController.view ];
//-------------------------------------------------------------------------------------
return YES;
}