我有一个带有 TabBar 和标签的 iPhone 应用程序。每个选项卡都加载了 UIViewControllers,我想要的特定选项卡是更改与选项卡关联的 UIViewController。当我调用 PresentViewController 时,它会更改 UIViewController 但也会隐藏我不想要的 TabBar。
谁能解释一下需要做什么?
谢谢
我有一个带有 TabBar 和标签的 iPhone 应用程序。每个选项卡都加载了 UIViewControllers,我想要的特定选项卡是更改与选项卡关联的 UIViewController。当我调用 PresentViewController 时,它会更改 UIViewController 但也会隐藏我不想要的 TabBar。
谁能解释一下需要做什么?
谢谢
UITabBarController 将其视图控制器的集合保存在一个恰当命名的属性中viewControllers。您可以在运行时修改它。有些副作用可能对您的应用程序很好,但请阅读文档以确保。
一种方便的方法(以及如何修改该不可变数组的说明)如下所示:
- (void)replaceTabBarViewControllerAtIndex:(NSUInteger)index with:(UIViewController *)newVC {
NSMutableArray *newVCs = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
if (index < newVCs.count) {
newVCs[index] = newVC;
self.tabBarController.viewControllers = [NSArray arrayWithArray:newVCs];
}
}
用新的 vc 调用它而不是显示它。