简体   繁体   English

我可以使用一个视图控制器在选项卡栏控制器中处理多个视图吗

[英]Can I use one view controller to handle multiple views in a tab bar controller

I am making an app with a tab bar which will display three different timers. 我正在制作一个带有标签栏的应用程序,它将显示三个不同的计时器。 The three timers are almost identical aside from the time and a few labels. 除了时间和一些标签外,这三个计时器几乎完全相同。 Currently I am using 3 view controllers on my story board for the timers which use the same class, and embedding these into a tab bar view controller. 目前,我在故事板上使用了3个视图控制器来使用相同类的计时器,并将它们嵌入到标签栏视图控制器中。 Is there a way I can have one view controller and then programmatically use it three times in the tab bar view controller? 有没有一种方法,我可以拥有一个视图控制器,然后在标签栏视图控制器中以编程方式使用它三遍? Is this even a good path to go down? 这是走下去的好路吗?

A view can only have one parent so you need three separate view instances to populate the three tabs. 一个视图只能有一个父视图,因此您需要三个单独的视图实例来填充三个选项卡。 And since a view controller only has one view, each of the view instances in the three tabs needs its own view controller instance. 而且,由于视图控制器只有一个视图,因此三个选项卡中的每个视图实例都需要自己的视图控制器实例。

You can have one view controller class with three instances of that view controller, but you can't use one view controller instance and its one view instance to populate three tabs. 您可以具有一个视图控制器类和该视图控制器的三个实例,但是不能使用一个视图控制器实例及其一个视图实例来填充三个选项卡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在一个View Controller中拥有多个Collection View? - How can I have multiple Collection Views in one View Controller? 如何在“标签栏”控制器中嵌入“拆分视图”控制器? - How can I embed Split View controller in Tab Bar controller? Xcode中选项卡栏控制器视图的第一个视图 - The first view of the tab bar controller views in xcode 我可以在同一View Controller中添加两个选项卡栏吗,底部一个选项卡栏,顶部一个选项卡栏 - Can i Add Two Tab Bars in same View controller one tab bar at bottom and one tab bar at top 一个具有多个视图的视图控制器 - one view controller with multiple views 一个视图控制器可以处理多少个子视图和表视图 - How many subviews and table views can one view controller handle 仅使用一个视图控制器的多个选项卡的选项卡栏 - Tab bar with multiple tabs using only one view controller 如何在标签栏控制器中从一个视图控制器切换到另一个视图控制器并保留标签栏? - How within a tab bar controller do I segue from one view controller to another and retain the tab bar? 以编程方式切换视图控制器以在选项卡栏控制器中显示视图 - Programmatically switch view controller to show views in Tab Bar Controller 如何在Tab栏控制器中使用一个Xib并创建多个视图控制器? [Objective-C] - How to use one Xib and create multiple view controllers in Tab bar controller ? [Objective-C]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM