你可以在UINavigationController内部推送一个UITabBarController吗 [英] Can you push a UITabBarController inside an UINavigationController

查看:78
本文介绍了你可以在UINavigationController内部推送一个UITabBarController吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否无法在UINavigationController内推送UITabBarController?我回读了旧版本的iOS,但是现在仍然如此吗?

Is it not possible to push a UITabBarController inside a UINavigationController? I read back in older versions of iOS but is that still the case now?

推荐答案

简单地说,是的,可以.

Simply putting it, YES you can.

但是仅仅因为您可以,并不意味着您应该这样做. UITabBarController旨在用作根级别的viewController(作为应用程序窗口的rootViewController).目的是为用户提供最佳(和简便)的用户体验. Apple建议保持应用程序的视图层次结构,以确保从一个视图控制器到另一个视图控制器只有一个路径".

But simply because you can, does not mean you should. The UITabBarController is intended to be used as a viewController at the root level (as the rootViewController of the app window). The aim is to provide the user with the best(and easy) UX. Apple advises to keep the view hierarchy of your app such that there is only one 'path' from one view controller to another.

使用UITabBarController的广泛接受的方法是将其设置为rootViewController,并将UIViewControllers分配给每个选项卡".如果您希望能够从这些视图控制器中推送/弹出,请为每个选项卡分配一个UINavigationController,并为其分配一个单独的rootViewController,就像iOS的Facebook应用一样.

The widely accepted way of using a UITabBarControlleris to set it as the rootViewController, and assign UIViewControllers to each 'tab'. If you want to be able to push/pop from these view controllers, you assign a UINavigationController to each tab, with their own rootViewControllers instead, just like the Facebook app for iOS.

如果您决定将其推送到UINavigationController上,建议您在每个选项卡中使用简单的viewControllers而不是UINavigationController来避免多个视图层次结构.其余的一切取决于您作为开发人员.在任何情况下,简化编码都不会影响最终用户的体验.优先级始终是后者.

If you do decide to push it onto a UINavigationController it would be advised to use simple viewControllers in each tab, rather than UINavigationControllers, to avoid multiple view hierarchies. The rest is upto you as a developer. In no scenario, should ease-of-coding affect the end user's experience. The priority is always the latter.

  1. 创建一个UITabBarController.

您可以使用以下命令为每个选项卡设置根视图控制器:

You set the root view controllers for each tab using:

tabBarController.viewControllers = [NSArray arrayWithObjects:
                                         alphaController,
                                         betaController,
                                         nil];

  • 将其放置到导航控制器上.

  • Push it onto your navigation controller.

    UITabBarController类(建议子类)的viewDidLoad方法中,将其设置为UITabBar的项目(UIBarButtonItems).

    In the viewDidLoad method of your UITabBarController class (advised to subclass), you set it's UITabBar's items (UIBarButtonItems).

    使用UITabBarControllerDelegate,您可以处理它们的选择.您不一定必须在选择选项卡时显示viewControllers.您可以通过覆盖shouldSelectViewController:方法来更改其行为.

    Using UITabBarControllerDelegate, you can handle their selection. You do not necessarily have to show viewControllers on selection of tabs. You can alter their behaviour by overriding the shouldSelectViewController: method.

    这篇关于你可以在UINavigationController内部推送一个UITabBarController吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆