【发布时间】:2017-05-06 19:01:28
【问题描述】:
我正在开发一个于 2011 年首次创建的 Objective-c iOS 应用程序,在 2013 年完成了一些更新和更改。现在我应该完成这项工作,因为它因错误而崩溃:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“应用程序窗口应在应用程序启动结束时具有根视图控制器”
在 AppDelegate 中我已经检查过:
[self.window setRootViewController:viewAfterLaunchScreen];
调试后,我注意到应用程序在 viewWillAppear 运行 rootViewController 后崩溃。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[DAL GetPreferences:@"FIRST"] isEqualToString:@"1"])
{
LoginViewController *lvc3 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
[self.window setRootViewController:lvc3];
[lvc3 release];
}
else if(_window.rootViewController == nil){
PagingViewController *lvc2 = [[PagingViewController alloc] initWithNibName:@"PagingViewController" bundle:nil];
[self.window setRootViewController:lvc2];
[lvc2 release];
}
[DAL SavePreference:@"FIRST" :@"1"];
[self.window makeKeyAndVisible];
return YES; }
【问题讨论】:
-
@Mahesh 在发布我的问题之前我已经检查了这个答案,并且我已经提到我已经检查了 setRootViewController。
-
显示您的
didFinishLaunchingWithOptions方法。 -
@Mahesh 请检查编辑后的帖子
-
在返回 YES 之前尝试
LoginViewController *lvc3 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; [self.window setRootViewController:lvc3];。如果问题仍然存在,请检查您的视图控制器是否为零。
标签: ios objective-c terminate