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