【问题标题】:blank rootviewcontroller page is added by default from iOS 4.3 and above从 iOS 4.3 及更高版本默认添加空白 rootviewcontroller 页面
【发布时间】:2011-10-19 21:22:57
【问题描述】:

我有一个应用程序,我在其中使用导航控制器通过 customViewControllers 呈现分层数据。然而,在我们的应用程序规范中,我们需要在每个页面中都有一个“主页按钮”,它应该将用户带回 rootviewcontroller 页面。为了实现这一点,我在所有自定义视图控制器中定义了一个 launchHomePage 方法,如下所示:

- (void) launchHomePage {
    [self.navigationController popToRootViewControllerAnimated:NO];
}

这在 iOS 4.2 上运行良好。然而,在 iOS4.3 和 iOS5 中,当单击“主页按钮”时,它会显示一个空白的表格视图。为了调试问题,我尝试在调用 popToRootViewControllerAnimated 之前查看 navigationController 中的 viewController 列表。

- (void) launchHomePage {

    if(self.navigationController) {

        [self printViewControllers:[self.navigationController viewControllers]];

        [viewController.navigationController popToRootViewControllerAnimated:NO];

    } else {
        NSLog(@"Couldn't retrieve navigationcontroller\n");
    }
}

- (void) printViewControllers:(NSArray *) viewControllers {

    if(viewControllers) {
        NSLog(@"Number of viewcontrollers in navigationController's array is %d\n", 
              [viewControllers count]);

        int i = 1;
        for(UIViewController *viewController in viewControllers) {
            NSLog(@"viewController %d is %@ and has title %@\n", i++, viewController, [viewController title]);
        }
    }
}

对于相同的执行顺序,以下是上述方法在iOS5.0和iOS4.2中的输出:

iOS5:

Number of viewcontrollers in navigationController's array is 3
viewController 1 is <RootViewController: 0x86259c0> and has title (null)
viewController 2 is <RootViewController: 0x9115680> and has title MainPage
viewController 3 is <FirstPageViewController: 0x9141bd0> and has title FirstPage


iOS4.2:
Number of viewcontrollers in navigationController's array is 2
viewController 1 is <RootViewController: 0x624d520> and has title MainPage
viewController 2 is <FirstPageViewController: 0x651ce10> and has title FirstPage

我无法弄清楚如何/为什么有一个空白页面(标题为 null)作为 navigationController 的根。感谢任何帮助解决这个问题。

【问题讨论】:

    标签: iphone cocoa-touch ipad ios5


    【解决方案1】:

    我遇到了同样的问题,我认为它与使用 xib 文件加载 UINavigationController 有关,但我无法确认。无论哪种方式,我最初都有这个(navcontroller 是从 xib 文件加载的 UINavigationController,所以我没有分配它,因为我认为 xib 文件这样做了):

    [navController initWithRootViewController:rootController];
    

    我把它换成了这个

    navController = [[UINavigationController alloc] initWithRootViewController:rootController];
    

    popToRootViewController 方法现在可以正常工作,在 iOS 4.3 和 iOS 5 之前的版本中。我还在 iOS 3.1.3 上对其进行了测试,并且可以正常工作。

    【讨论】:

      猜你喜欢
      • 2014-02-14
      • 1970-01-01
      • 2012-04-06
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多