当应用程序启动时,如果在故事板中选择rootViewController
或者我在application:didFinishLaunchingWithOptions:
中按代码设置它,则无关紧要,应用程序崩溃,因为它正在尝试调用方法{{1} }
此处handleKeyEvent:
代码:
application:didFinishLaunchingWithOptions:
这是控制台输出:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (!self.window) {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *loginViewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
if (self.window.rootViewController) {
[self.window.rootViewController presentViewController:loginViewController
animated:NO
completion:nil];
} else if (![self.window.rootViewController isKindOfClass:loginViewController.class]) {
[self.window setRootViewController:loginViewController];
}
return YES;
}
可能有人知道会发生什么?
更新
这似乎是一个iOS错误。重新启动设备后,一切正常。
答案 0 :(得分:0)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *loginViewController = (LoginViewController *) [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
if (self.window.rootViewController) {
[self.window.rootViewController presentViewController:loginViewController
animated:NO
completion:nil];
} else if (![self.window.rootViewController isKindOfClass:loginViewController.class]) {
[self.window setRootViewController:loginViewController];
}
[self.window makeKeyAndVisible];
return YES;
}