“应用程序窗口应该在应用程序启动结束时有一个根视图控制器"仅在 iPad 上出错 [英] "Application windows are expected to have a root view controller at the end of application launch" error only on iPad

查看:23
本文介绍了“应用程序窗口应该在应用程序启动结束时有一个根视图控制器"仅在 iPad 上出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 iPhone 专用应用程序转换为通用应用程序.我将设备切换到 Universal 并让 Xcode 为我制作 MainWindow-iPad.xib,现在当我在 iPhone 模拟器中运行该应用程序时它工作正常,但是当我在 iPad 模拟器中运行它时我得到一个白色screen 和 应用程序窗口在应用程序启动结束时应该有一个根视图控制器 错误.我已经阅读了一些关于同一问题的其他帖子,但没有一篇文章仅限于一台设备.

I am trying to convert my iPhone only application to a Universal application. I switched the devices to Universal and let Xcode do it's thing making a MainWindow-iPad.xib for me, and now when I run the app in the iPhone simulator it works fine, but when I run it in the iPad simulator I get a white screen and the Application windows are expected to have a root view controller at the end of application launch error. I have read some other posts about this same problem but none of them are just limited to one device.

这是我的 application:didFinishLaunchWithOptions: 方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

 /* some dropbox setup stuff */


// INIT VIEW AND CORE DATA
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
    // Handle the error.
}

rootViewController.managedObjectContext = context;

UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;

[_window addSubview:[_navigationController view]];
[_window makeKeyAndVisible];

[rootViewController release];
[aNavigationController release];

return YES;
}

我只有一个大小适合 iPhone 的根视图控制器,称为 RootViewController.但它仍然应该加载,不是吗?或者,如果不应该,我该如何为 iPad 创建一个?

I just have one root view controller that is sized for iPhone called RootViewController. But it should still load in shouldn't it? Or if it shouldn't how do I create one for iPad?

推荐答案

更改以下行:

[_window addSubview:[_navigationController view]];

到:

_window.rootViewController = _navigationController;

或者,如果您需要 iOS 3 兼容性:

or, if you need iOS 3 compatibility:

if ([_window respondsToSelector:@selector(setRootViewController:)]) {
    _window.rootViewController = _navigationController;
} else {
    [_window addSubview:_navigationController.view];
}

这篇关于“应用程序窗口应该在应用程序启动结束时有一个根视图控制器"仅在 iPad 上出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆