在Xcode 7中,iOS 9“应用程序窗口应该在应用程序启动结束时具有根视图控制器”

前端之家收集整理的这篇文章主要介绍了在Xcode 7中,iOS 9“应用程序窗口应该在应用程序启动结束时具有根视图控制器”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的控制台出错并崩溃了.
“Application windows are expected to have a root view controller at the end of application launch”

下面是我的一段代码,在输入返回YES行后会发生崩溃.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    

    UIImageView *defaultImage = [[UIImageView alloc] initWithImage:splashImage];
    defaultImage.frame = defaultImageFrame;
    [self.window addSubview:defaultImage];

    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self
                                   selector:@selector(login:)
                                   userInfo:nil
                                    repeats:NO];
    [self.window setBackgroundColor:[UIColor clearColor]];
    [self.window makeKeyAndVisible];


    return YES; // here crash will happens
}


-(void)login:(id)sender
{
   PreLoginViewController *appController = [[PreLoginViewController alloc] initWithNibName:nil bundle:nil];
            if (_ChooseLogin.isStatus == 105)
            {
                flagrequired = @"1";
                appController.serverDownFlag = @"1";
            }
            appController.termsURL = _ChooseLogin.urlString;

            appController._ChooseLogin = _ChooseLogin;
            appController.rootNetworkAvailable = NO;
            appController.verionMsg = versionStr;
            [dft setBool:NO forKey:@"isNeedActivate"];
            appController.isNeedActivate = NO;
            navigationController = [[UINavigationController alloc]
                                    initWithRootViewController:appController];

}

谁知道如何解决这个问题?它在iOS 8中运行良好,直到Xcode 6.3.

解决方法

您需要在didFinishLaunchingWithOptions中调用setRootViewController:并且您需要一个视图控制器来执行此操作.

代码中:

UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:defaultImage]; 
[self.window setRootViewController:vc];

猜你在找的iOS相关文章