【问题标题】:Xcode 7 beta ios 9 giving error 'Application windows are expected to have a root view controller at the end of application launch'Xcode 7 beta ios 9 给出错误“应用程序窗口应该在应用程序启动结束时有一个根视图控制器”
【发布时间】:2015-11-17 15:43:43
【问题描述】:

这是我的代码。我也在使用 MTStatusBarOverlay。此代码在使用 xcode 6 运行时正常工作。应用程序崩溃并给出错误

'应用程序窗口应该有一个根视图控制器 应用程序启动结束。

我尝试以多种不同的方式设置 rootViewController。我什至尝试在 MTStatusBarOverlay 中覆盖以下代码

     - (UIViewController *)rootViewController {
         ETAppDelegate *delegate = (ETAppDelegate *)[UIApplication sharedApplication].delegate;
         return delegate.window.rootViewController;
     }


     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
         _didReceiveBackgroundNotification = NO;


         [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge];

         NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

         MTStatusBarOverlay *overlay = [MTStatusBarOverlay sharedInstance];
         overlay.animation = MTStatusBarOverlayAnimationNone;
         overlay.hidesActivity = YES;

         NSDictionary *bundleDictionary = [[NSBundle mainBundle] infoDictionary];
         NSString *currentVersion = [NSString stringWithFormat:@"%@ (%@)", [bundleDictionary objectForKey:@"CFBundleShortVersionString"], [bundleDictionary objectForKey:@"CFBundleVersion"]];

        [overlay postMessage:@"Test Application" stringByAppendingString:currentVersion]];

        [self.window makeKeyAndVisible];

        return YES;
    }



    - (UIWindow *)window{
       if (_window) return _window;

       _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
       [_window setRootViewController:self.rootViewController];

       return _window;
  }


  - (UIViewController *)rootViewController{
       if (_rootViewController) return _rootViewController;
       _rootViewController = [[ETNavigationController alloc] initWithNibName:nil bundle:nil];

       ETHomeMenuViewController *homeViewController = [[ETHomeMenuViewController alloc] initWithNibName:nil bundle:nil];
                  ((ETNavigationController*)_rootViewController).rootViewController = homeViewController;
      homeViewController = nil;
      return _rootViewController;
 }

【问题讨论】:

    标签: ios xcode7


    【解决方案1】:

    因为MTStatusBarOverlayUIWindow 的子类,Xcode 7 现在指定如错误消息所述:

    应用程序窗口应该在应用程序启动结束时有一个根视图控制器

    这意味着您无法在应用程序启动之前实例化没有根 viewcontrollerUIWindow。所以在应用程序启动之前不要打电话给[MTStatusBarOverlay sharedInstance]

    【讨论】:

      猜你喜欢
      • 2015-11-03
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多