2015-09-22 9 views
8

iOS9で次のエラーが発生しています。アサーションエラー - [UIApplication _runWithMainScene:transitionContext:completion:]、

はここに私のコードです: -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"login_dict"]) 
    { 
     if ([[NSUserDefaults standardUserDefaults] objectForKey:@"isLogout"] == nil || [[[NSUserDefaults standardUserDefaults] objectForKey:@"isLogout"] integerValue]== 0) 
     { 
      self.loginDict = [[BaseViewController sharedInstance] removeNullFromDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"login_dict"]]; 
      self.firstViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil]; 
     } 
     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isLogout"] integerValue]== 1) 
     { 
      self.firstViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil]; 
     } 
     NSLog(@"Userinfo = %@",self.loginDict); 
    } 
    else 
    { 
     self.firstViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil]; 
    } 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    self.navigationController = [[BufferedNavigationController alloc] initWithRootViewController:self.firstViewController]; 
    //[window makeKeyAndVisible]; 

    [self.window setRootViewController:self.navigationController]; 
} 

注:このコードは、Xcodeの6.4とiOS8で正常に動作しています。ここ

Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UIApplication.m:3294 

答えて

2

私はnavigationControllerがnilであるかどうかをチェックすることによって、解決策を得た: - :

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

そして、それはそれを修正

if (self.navigationController== nil) 
{ 
    self.navigationController = [[BufferedNavigationController alloc] initWithRootViewController:self.firstViewController]; 
} 
else 
{ 
    [self.navigationController setViewControllers:@[self.firstViewController] animated:NO]; 
} 
5

私はアプリケーションdidFinishLaunchingWithOptionsからこの行を削除する必要がありました私のために。この行を使用して

2

は私の問題(iOSの10)を解く:

[self.window setRootViewController:self.navigationController]; 

は(古いiOSとXcodeのために働いていた)であった:

[self.window addSubview:navigationController.view]; 
関連する問題