在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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...