Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 导航实例的不确定性:UITabBarController_Ios_Objective C_Uitabbarcontroller_Multiple Instances - Fatal编程技术网

Ios 导航实例的不确定性:UITabBarController

Ios 导航实例的不确定性:UITabBarController,ios,objective-c,uitabbarcontroller,multiple-instances,Ios,Objective C,Uitabbarcontroller,Multiple Instances,在我的应用程序中,我有一个UITabBarController,它被设置为初始视图控制器,并具有脚本ID“TabBarControl”。TabBarControl有4个选项卡,在第二个选项卡(索引1)之外有一系列的UIViewController导航,其中VC是ViewController UINavigationControllerUINavigationController('branchesControl')>VC1('branchesView')>UINavigationControll

在我的应用程序中,我有一个
UITabBarController
,它被设置为初始视图控制器,并具有脚本ID“TabBarControl”。TabBarControl有4个选项卡,在第二个选项卡(索引1)之外有一系列的
UIViewController
导航,其中VC是
ViewController

UINavigationController
UINavigationController
('branchesControl')>VC1('branchesView')>
UINavigationController
>VC2>
UINavigationController
>VC3>
UINavigationController
>VC4

我在VC4的导航栏上有一个名为“确认”的
UIBarButtonItem
。“确认”按钮触发以下iAction方法:

- (IBAction)confirmClicked:(UIBarButtonItem *)sender
{
    //EXECUTE NAVIGATION
    UITabBarController * tabControl = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
    tabControl.selectedIndex = 1;

    [self presentViewController:tabControl animated:YES completion:nil];
}
目标是从VC4导航回原始的“branchesView”

问题是,我注意到VC2的导航栏上的uibarbuttonite的一组手动颜色在点击“确认”,然后重新访问视图堆栈后重置为默认白色。我相信我正在创建多个实例

如何在不创建新实例的情况下导航回branchesView,然后导航回VC2


PS我不确定新实例是TabBarController还是branchesView,我只知道我似乎是用
confirmClicked:
方法创建了多个实例。

而不是返回到现有的
branchesView
,您正在演示一个新的
UITabBarController
,其中包含一组全新的子视图控制器,这几乎肯定不是您想要做的

相反,您需要跳回要返回的现有视图控制器。您可以通过引用或索引来实现这一点,在您的情况下,只需弹出到根目录即可(前提是您想要访问的视图控制器确实位于根目录下)

您可以简单地执行以下操作:

[self.navigationController popToRootViewControllerAnimated:YES];
您的问题还使堆栈中的每个视图控制器似乎都包装在一个新的导航控制器中。如果是这样的话,您也需要解决这个问题。您不应该嵌套
UINavigationControllers
。相反,每个选项卡都有一个单独的根目录,每次要将新的
UIViewController
推送到堆栈上时,调用:

[self.navigationController pushViewController:viewControllerToPush animated:YES];

非常感谢。这是我很久以来得到的最有用的答案。告诉我,每次都使用segues而不是
pushViewController:
来导航是否可以?你建议离开branchesControl,去掉所有其他的
UINavigationController
?应该没问题,是的。是的,每个选项卡上只有一个
UINavigationController
,并且去掉其他选项卡。太棒了,我不知道为什么,但这总是让我困惑。我建议阅读和。他们有一些图片和图表,可以帮助你了解这些组件中的层次结构。我已经完整地阅读了这两个部分。。它们对我现在或过去阅读它们都没有意义,当我试图删除
UINavigationController
s时,我的
NavBar