我做了一个简单的基于导航的应用程序。 它非常适用于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解决它?
答案 0 :(得分:5)
UIWindow在iOS<中没有rootViewController属性4.0。因此,您需要检查版本(google it)然后设置rootViewController,或者根据用户运行的版本将navigationController的view
作为子视图添加到窗口中,如下所示。:
[self.window addSubview:self.navigationController.view];
快速编辑:要检查是否可以使用rootViewController属性,可以检查[self.window respondsToSelector:@selector(setRootViewController)]
是否返回TRUE或FALSE。
答案 1 :(得分:1)
正确的方法是(别忘了“:”!):
if ( [self.window respondsToSelector:@selector(setRootViewController:)] )
self.window.rootViewController = self.tabBarController;
else
[self.window addSubview: self.tabBarController.view];