【问题标题】:Setting rootViewController for ipad 3.2 doesnt work为 ipad 3.2 设置 rootViewController 不起作用
【发布时间】:2011-08-03 09:09:22
【问题描述】:

我做了一个简单的基于导航的应用程序。 它在 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 的问题?

【问题讨论】:

    标签: iphone ipad uinavigationcontroller rootview


    【解决方案1】:

    UIWindow 在 iOS view 作为子视图添加到窗口,如下所示。:

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

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

    【讨论】:

    • 太棒了,它适用于所有 iOS 版本。我想我不需要检查版本。因为我没有在 IB 中设置视图控制器。谢谢...
    【解决方案2】:

    正确的做法是(别忘了“:”!):

    if ( [self.window respondsToSelector:@selector(setRootViewController:)] )
        self.window.rootViewController = self.tabBarController;
    else
        [self.window addSubview: self.tabBarController.view];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 2012-01-02
      • 2021-09-30
      • 2021-12-17
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      相关资源
      最近更新 更多