[英]iOS check if ViewController instance is open and switch ViewControllers
I have a base ViewController with embedded NavigationController to provide a ToolBar. 我有一个带有嵌入式NavigationController的基本ViewController,以提供一个ToolBar。 The ToolBar has three buttons used to call ViewControllers by segue to present the data.
工具栏上有三个按钮,用于通过segue调用ViewController来呈现数据。
Showing and dismissing each data ViewController bit by bit is no problem but I would like to switch between all three data presenting ViewControllers but without dismissing and reopening ViewControllers multiple times. 一点一点地显示和消除每个数据ViewController没问题,但是我想在所有三个呈现ViewController的数据之间切换,但又不想多次解除和重新打开ViewController。
The base ViewController is part of a TabBarController. 基本ViewController是TabBarController的一部分。 So, I don't want to create another one for VC1 - 3. My target is to use buttons to switch between VC1, 2 and 3 but I don't know how to start.
因此,我不想为VC1-3创建另一个。我的目标是使用按钮在VC1、2和3之间切换,但是我不知道如何启动。 I tried to find opened ViewController using:
我试图使用以下方法找到打开的ViewController:
ViewController1 *presenter = [(UITabBarController *)self.presentingViewController viewControllers][0];
But it just tells me that the NavigationController is the presenting ViewController. 但这只是告诉我NavigationController是呈现的ViewController。 But there is no way to asks for ViewControllers opened by the NavigationController.
但是没有办法要求由NavigationController打开的ViewController。 Any ideas?
有任何想法吗?
Thanks! 谢谢!
Okay, I think I finally understand what you're doing. 好吧,我想我终于明白了你在做什么。 You have a base view controller with a toolbar.
您具有带有工具栏的基本视图控制器。 Clicking any of the three buttons on the toolbar will present one of three view controllers.
单击工具栏上的三个按钮中的任何一个将显示三个视图控制器之一。 These view controllers also display a toolbar, which allows you to toggle between those three view controllers, but you want those view controllers to persist as the user switches between them.
这些视图控制器还显示一个工具栏,该工具栏允许您在这三个视图控制器之间切换,但是您希望这些视图控制器在用户在它们之间切换时保持不变。 When the user is finished, they can click the back button on the navigation bar to pop all those view controllers and return to the base view controller.
用户完成操作后,他们可以单击导航栏上的后退按钮以弹出所有这些视图控制器,并返回到基本视图控制器。 Is that right?
那正确吗?
Is it necessary to for the child view controllers to use a toolbar and not a UITabBarController
? 子视图控制器是否必须使用工具栏而不是
UITabBarController
? The UITabBarController
would maintain a reference to all three view controllers for you, and you wouldn't have to segue between them. UITabBarController
会为您维护对所有三个视图控制器的引用,而您不必在它们之间进行选择。 For example, the base view controller could still have three buttons, and the buttons would pushViewController:animated:
a new UITabBarController
with three view controllers, and it would also choose the selected view controller depending on which button was pressed. 例如,基本视图控制器仍然可以具有三个按钮,并且按钮将
pushViewController:animated:
具有三个视图控制器的新UITabBarController
,并且还将根据所按下的按钮来选择选定的视图控制器。 That might make things a lot easier for you. 这可能会使事情变得容易得多。
The reason I propose this is that I think trying to use the navigation controller to segue between those three VCs is not the right usage of a navigation controller. 我之所以提出这个建议,是因为我认为尝试使用导航控制器在这三个VC之间进行筛选不是正确的导航控制器用法。 Segues like this are meant to convey a hierarchical relationship between these VCs, but they seem like siblings and not children of each other.
这样的Segues旨在传达这些VC之间的等级关系,但它们看起来像兄弟姐妹,而不是彼此的孩子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.