Iphone 如何在TabBarController的选项卡中更改UIViewController

Iphone 如何在TabBarController的选项卡中更改UIViewController,iphone,tabs,uitabbarcontroller,viewcontroller,Iphone,Tabs,Uitabbarcontroller,Viewcontroller,我有一个带有TabBar和tabs的iPhone应用程序。每个选项卡都加载了UIViewController,对于特定选项卡,我希望更改与该选项卡关联的UIViewController。当我调用PresentViewController时,它会更改UIViewController,但也会隐藏我不想要的选项卡栏 有人能解释一下需要做什么吗 谢谢UITabBarController在一个名为ViewController的属性中保存了它的视图控制器集合。您可以在运行时对此进行修改。有一些副作用可能对你

我有一个带有TabBar和tabs的iPhone应用程序。每个选项卡都加载了UIViewController,对于特定选项卡,我希望更改与该选项卡关联的UIViewController。当我调用PresentViewController时,它会更改UIViewController,但也会隐藏我不想要的选项卡栏

有人能解释一下需要做什么吗


谢谢

UITabBarController在一个名为
ViewController
的属性中保存了它的视图控制器集合。您可以在运行时对此进行修改。有一些副作用可能对你的应用程序是好的

一种方便的方法(以及如何修改该不可变数组的示例)如下所示:

- (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];
    }
}
-(void)用:(UIViewController*)newVC替换tabbarviewcontrolleratindex:(NSUInteger)索引{
NSMutableArray*newVCs=[NSMutableArray arrayWithArray:self.tabBarController.ViewController];
如果(索引

用新的vc调用它,而不是演示它。

谢谢,非常有用,只是一个小的mod NSMutableArray*newVCs=[NSMutableArray arrayWithArray:self.tabBarController.viewControllers]dahn你能解释一下为什么我使用上述方法加载视图后,选项卡栏图像会消失吗?我改变了两次视图,第二次它消失了,选项卡变为空白。Ok Dahn解决了忘记在每个视图中为选项卡加载图像的问题