简体   繁体   English

iOS检查ViewController实例是否打开并切换ViewController

[英]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。

  1. how do I keep the ViewController 1 - 3 open when switching between VC1 - 3? 在VC1-3之间切换时,如何保持ViewController 1-3打开?
  2. How do I know if a data presenting ViewController (VC1 - 3) is already open? 我怎么知道显示ViewController(VC1-3)的数据是否已经打开?
  3. How do I dismiss all open ViewControllers (VC1 - 3) when VC1, VC2 or VC3 is dismissed to go back to the base ViewController? 当关闭VC1,VC2或VC3以返回到基本ViewController时,如何关闭所有打开的ViewController(VC1-3)?

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.

相关问题 无法在Swift中的其他ViewController中为ViewController创建实例 - Not able to create instance for viewcontroller in other viewcontrollers in Swift 多个ViewControllers(containerView?childView?viewController实例?) - multiple ViewControllers (containerView? childView? instance of viewController?) iOS 6在模态呈现的视图控制器中推送视图控制器 - iOS 6 pushing viewcontrollers in a modally presented viewcontroller iOS:切换到第二个ViewController - iOS: switch to second ViewController 不使用容器viewControllers切换ViewController的最佳方法是什么? - What is the best way to switch ViewController without using container viewControllers? 在iOS上以编程方式切换到备用ViewController - Switch to alternate ViewController programmatically on iOS iOS控制器模式-通过3个视图控制器的相同实例 - iOS Controller Pattern - same instance through 3 viewcontrollers iOS如何在多个ViewController中的一个ViewController中启动按钮? - iOS how to make button in one ViewController start actions in many ViewControllers? 检查用于在viewController本身中打开viewController的segue - check the segue used to open viewController in the viewController itself 如何在iOS中打开现有的ViewController - How to open an existing viewcontroller in ios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM