出现在具有多于5个项目的选项卡栏中的moreViewController似乎正确对待视图控制器,但不处理导航控制器。任何人都可以解释为什么这是事实吗?iPhone标签栏moreNavigationController无法正确处理导航控制器?
下面是如何重现该问题的散文,然后在代码:
创建与6片6个UIViewControllers一个简单的应用程序。由于我有超过5个选项卡,选项卡“5”和“6”驻留在moreNavigationList中。 第6个标签包含一个按钮,按下该按钮可删除第一个标签。这将选项卡的数量减少到5,因此不再需要moreNavigationController并消失。标签“6”现在移动到标签栏的最后一个位置。一切都如预期。
现在,如果将视图控制器从标签“6”(即带有按钮的视图控制器)放到导航控制器中,事情就会中断。如果我按下按钮,选项卡“1”将从标签栏中删除,moreNavigationController消失,并且标签栏“6”现在显示在标签栏的最后一个位置。但它的内容已经消失。没有按钮,没有任何东西。
从分析视图层次结构看,似乎发生的事情是moreNavigationController从[tabBarController viewControllers]中的原始导航控制器中移除了“6”视图控制器并将其添加到其自己的堆栈中。但是当moreNavigationController消失时,它似乎不会放回去。
这是我用来重现这一个简单的基于窗口的测试程序的代码:使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create a tab bar with 5 regular view controllers and a navigation controller
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
UIViewController* vc1 = [[[UIViewController alloc] init] autorelease]; vc1.title = @"1";
UIViewController* vc2 = [[[UIViewController alloc] init] autorelease]; vc2.title = @"2";
UIViewController* vc3 = [[[UIViewController alloc] init] autorelease]; vc3.title = @"3";
UIViewController* vc4 = [[[UIViewController alloc] init] autorelease]; vc4.title = @"4";
UIViewController* vc5 = [[[UIViewController alloc] init] autorelease]; vc5.title = @"5";
UIViewController* vc6 = [[[UIViewController alloc] init] autorelease]; vc6.title = @"6";
// Add a button that removes tab "1" when pressed to vc6
UIButton *moveButton = [self moveButton];
[vc6.view addSubview:moveButton];
vc6.view.backgroundColor = [UIColor greenColor];
moveButton.center = vc6.view.center;
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:vc6] autorelease];
// Everything is fine if vc6 is added directly instead of inside a navigation controller
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, vc4, vc5, navController, nil];
tabBarController.viewControllers = controllers;
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (UIButton *)moveButton
{
UIButton *moveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
moveButton.frame = CGRectMake(0, 0, 150, 50);
[moveButton setTitle:@"Remove 1" forState:UIControlStateNormal];
[moveButton addTarget:self action:@selector(remove) forControlEvents:UIControlEventTouchUpInside];
return moveButton;
}
- (void)remove
{
// remove 1st tab bar item (this also removes moreNavigationController)
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
[viewControllers removeObjectAtIndex:0];
[tabBarController setViewControllers:viewControllers];
}
SDK 4.3
您是否找到解决该问题的方法?我被困在迫使moreNavigationController弹出推控制器,以便控制器回到原来的导航堆栈...我发现UIKit的私有'UIMoreNavigationController'类有一个私有的'-_restoreOriginalNavigationController'方法,但它只是说moreNavigationController混乱导航堆栈。 – matm 2012-10-17 12:40:20