应用程序启动时,UIViewController尝试调用handleKeyEvent:方法

时间:2016-02-11 09:25:53

标签: ios objective-c

当应用程序启动时,如果在故事板中选择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错误。重新启动设备后,一切正常。

1 个答案:

答案 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;
    }