在Xcode 7中,iOS 9“应用程序窗口应该在应用程序启动结束时具有根视图控制器”
2020年02月04日
作者:佚名
我的控制台出错并崩溃了.
“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];
以上是来客网为你收集整理的在Xcode 7中,iOS 9“应用程序窗口应该在应用程序启动结束时具有根视图控制器”全部内容,希望文章能够帮你解决在Xcode 7中,iOS 9“应用程序窗口应该在应用程序启动结束时具有根视图控制器”所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。