UITabBarController使用须知

来源:互联网 发布:淘宝联盟分享了没9有钱 编辑:程序博客网 时间:2024/06/04 19:44

UITabBarController在我们的开发中经常被用到。关于它的使用,有几个须要注意的地方:
1、UITabBarController会抗拒和别的视图控制器组合,所以最好只将UITabBarController做为整个App的根视图。

 When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.  [Apple]
苹果的官方文档里要求我们将UITabBarController实例做为整个应用的“根”,这是最为被苹果接受的用法。
参考:http://blog.zhaojie.me/2010/12/iphone-composition-resistant-uitabbarcontroller.html

        http://stackoverflow.com/questions/8929462/uinavigationcontroller-pushing-uitabbarcontroller-only-displays-one-tab

2、最好不要去子类化UITabBarController。
This class is not intended for subclassing. Instead, you use instances of it as-is to present an interface that allows the user to choose between different modes of operation. [Apple]
苹果建议我们最好不要去子类化它,这个类主要被设计用来管理多个view controller并且展示多个view。

3、UITabBarController的viewControllers数组中不要出现相同的指针,标签栏控制器不会为相同的指针创建有效的标签。
Because selecting a tab replaces the contents of the interface, the type of interface managed in each tab need not be similar in any way. [Apple]