1

我做了一个简单的基于导航的应用程序。它在 iphone 上运行得很好,但它在 ipad 3.2 模拟器和设备上不起作用。

在 applicationdidfinish 事件中;

MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
[self.navigationController pushViewController:viewController animated:NO];
self.window.rootViewController = self.navigationController;
[viewController release];

它对这一行说:

self.window.rootViewController = self.navigationController;

[UIWindow setRootViewController:]:无法识别的选择器发送到实例 0x4c22dd0

但它适用于 ipad 4.2 及更高版本。

如何解决 ipad 3.2 的问题?

4

2 回答 2

5

UIWindow 在 iOS < 4.0 中没有 rootViewController 属性。因此,您需要检查版本(google it),然后设置 rootViewController,或者view根据您的用户正在运行的版本,将 navigationController 作为子视图添加到窗口,如下所示:

[self.window addSubview:self.navigationController.view];

快速编辑:检查是否可以使用 rootViewController 属性,可以检查是否[self.window respondsToSelector:@selector(setRootViewController)]返回 TRUE 或 FALSE。

于 2011-04-11T20:25:58.227 回答
1

正确的方法是(不要忘记“:”!):

if ( [self.window respondsToSelector:@selector(setRootViewController:)] )
    self.window.rootViewController = self.tabBarController;
else
    [self.window addSubview: self.tabBarController.view];
于 2012-02-29T11:14:59.000 回答