我的控制台出错并崩溃了.
“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];