简体   繁体   English

我可以将UITabBarController用作简单的viewController切换器吗?

[英]Can I use UITabBarController as a simple viewController switcher?

I'm creating an iPad app based on a UINavigationController (with the bar hidden) so I can push and pop other viewControllers for navigation around the app. 我正在基于UINavigationController创建一个iPad应用程序(隐藏了该栏),因此我可以推和弹出其他viewControllers来在应用程序中导航。 However, I am now wanting to add a section in which there are two viewControllers that I want to be able to switch between, so in other words they are side-by-side, rather than hierarchical. 但是,我现在想添加一个部分,其中有两个我希望能够在它们之间进行切换的viewController,也就是说,它们是并排的,而不是分层的。

Is it okay to use a UITabBarController for this? 为此可以使用UITabBarController吗? I am aware that on the iPhone it is recommended they are used only at the root level of the app, but since this is an iPad app I wondered if I could use it? 我知道在iPhone上建议仅在应用程序的根目录下使用它们,但是由于这是iPad应用程序,我想知道是否可以使用它? Also, I guess I need to create an empty viewController, create a UITabBarController within it and set the delegate to it, then add the two viewControllers to it... So in effect I will have a viewController within another viewController, and when I have done that in the past the results have been very flaky. 另外,我想我需要创建一个空的viewController,在其中创建一个UITabBarController并将其设置为委托,然后向其中添加两个viewControllers。因此,实际上,我将在另一个viewController中拥有一个viewController,当我拥有过去,这样做的结果非常不稳定。

Can I do it this way? 我可以这样吗? The only other way I can think of doing it is to have two plan UIView s within a UIViewController , but that also means I shouldn't really put any business logic in them (bad MVC!), and not being able to will be a right pain in the a**. 我能想到的唯一另一种方法是在UIViewController具有两个计划的UIView ,但这也意味着我不应该在其中真正放置任何业务逻辑(糟糕的MVC!),并且不能成为右疼痛在**。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

:-Joe :-乔

EDIT: I also need to be able to swipe-animate between the two VCs within the TabBarController, AND have a menubar over the top which doesn't animate... Can I do this? 编辑:我还需要能够在TabBarController中的两个VC之间滑动动画,并且在顶部没有动画的菜单栏...我可以这样做吗?

Sure. 当然。

I do this kind of thing all over the place in an app I'm working on. 我在我正在开发的应用程序中到处都是这种事情。 I actually have several different types of "toolbars" that can be optionally shown at different times. 实际上,我有几种不同类型的“工具栏”,可以选择在不同时间显示。

What I do is create a "parent" member in my toolbar's class - and when a button is pressed, I have the toolbar call a method in the parent class to do whatever needs to be done - (ie display another view). 我要做的是在工具栏的类中创建一个“父”成员-按下按钮时,工具栏会在父类中调用一个方法来执行需要做的任何事情-(即显示另一个视图)。

This avoids the whole mess of creating a view inside another view (or viewcontroller inside another viewcontroller - or whatever) - the toolbar can take the button hits, but all the views are opened by the root view/controller. 这避免了在另一个视图内(或另一个视图控制器内的viewcontroller-或其他)创建视图的整个过程,避免了工具栏可以单击按钮的情况,但所有视图均由根视图/控制器打开。

Hope this helps/makes sense! 希望这对您有所帮助!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM