【发布时间】: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