【问题标题】:Old iOS application crashes after launch screen旧 iOS 应用程序在启动屏幕后崩溃
【发布时间】:2017-05-06 19:01:28
【问题描述】:

我正在开发一个于 2011 年首次创建的 Objective-c iOS 应用程序,在 2013 年完成了一些更新和更改。现在我应该完成这项工作,因为它因错误而崩溃:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“应用程序窗口应在应用程序启动结束时具有根视图控制器”

在 AppDelegate 中我已经检查过:

[self.window setRootViewController:viewAfterLaunchScreen];

根据这个答案"Application windows are expected to have a root view controller at the end of application launch" error when running a project with Xcode 7, iOS 9

调试后,我注意到应用程序在 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; }

【问题讨论】:

标签: ios objective-c terminate


【解决方案1】:

这个“旧”项目有多少年了?如果超过几年,你还有没有:

[window addSubview:viewController.view];

您应该将其替换为:

[window setRootViewController:viewController];

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 2018-01-26
    相关资源
    最近更新 更多