【问题标题】:In Xcode 7, iOS 9 "Application windows are expected to have a root view controller at the end of application launch"在 Xcode 7 中,iOS 9 “应用程序窗口应在应用程序启动结束时有一个根视图控制器”
【发布时间】:2015-11-03 06:42:54
【问题描述】:

我的控制台出现错误并崩溃。

“Application windows are expected to have a root view controller at the end of application launch”  

下面是我的一段代码,输入return YES后会出现crash。

 - (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。

【问题讨论】:

  • 如果您使用的是 beta 5,请尝试使用 bundle:[NSBundle mainBundle] 而不是 bundle:nil
  • 它没有进入登录功能@Vin
  • 你在哪里调用了登录功能?
  • 在 NSTimer @ErsinSezgin 的 3.0 区间内
  • 你试过不带定时器吗?

标签: ios objective-c


【解决方案1】:

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

在代码中:

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

【讨论】:

  • 顺便说一句,如果您在应用程序中创建多个窗口 - 所有这些窗口都必须在应用程序启动结束时分配 rootViewController(在 IOS 9 中)
猜你喜欢
  • 2015-12-16
  • 2015-11-17
  • 1970-01-01
  • 1970-01-01
  • 2012-04-08
  • 1970-01-01
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多