应用程序窗口应该有一个根视图控制器?

时间:2015-11-10 00:26:08

标签: ios objective-c

我正在为我的客户端更新一个非常古老的应用程序,但我甚至无法在模拟器上运行它。它使用.xib文件而不是.storyboard。当我运行它时,我在调试日志中收到此错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

这是我在App Delegate中的代码:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

[AudioDatabase createDatabaseIfNeeded];

[EmailView createDatabaseIfNeeded];
[EmailView updateDatabaseIfNeeded];

if ([self isEmailView] == YES &&
    [EmailView shouldShowEmailView] == YES) {
    // the first view is the "Email View"

    [self goToEmailView];
} else {
    [self goToAudio];
}
}

- (void)goToEmailView {
InitialEmailViewController * currentView = [[InitialEmailViewController alloc] initWithNibName:@"InitialEmailViewController" bundle:nil];     

//CGRect rect = [[UIScreen mainScreen] bounds];
//[window setFrame:rect];

CGRect appRect = [[UIScreen mainScreen] applicationFrame];

[window setFrame:appRect];

[window addSubview:currentView.view];
[window makeKeyAndVisible];
}

- (void)goToAudio {
NSString * currentTrack = [AudioDatabase getLastTrack];

if (currentTrack != nil) {
    lastTrack = currentTrack;
    NSLog(@"DEBUG: set lastTrack to %@", lastTrack);
}

CGRect rect = [[UIScreen mainScreen] bounds];
[window setFrame:rect];

//CGRect appRect = [[UIScreen mainScreen] applicationFrame];
//[viewController.view setFrame:appRect];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
// Override point for customization after app launch
[window addSubview:navController.view];
//[self.view addSubview:navController.view];
[window makeKeyAndVisible];
}

和main.m:

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}

任何建议都会很棒!我看了很多,发现了很多解决方案,但似乎没有一个对我有用。

0 个答案:

没有答案