UINavigationController方法pushViewController:参数不能传递UITabBarController原因猜想
来源:互联网 发布:淘宝缺货赔付规则 编辑:程序博客网 时间:2024/05/29 11:19
最近做的一个项目界面如下:
UINavigationController
---->UITabBarController
但是看到pushViewController方法中有这样的描述:
"The view controller to push onto the stack. This object cannot be a tab bar controller. "
感到疑惑,为何UINavigationController could be embedded in UITabBarController,反之则不行呢?
转化一下如下:
- UITabBarController -> UINavigationController(YES)
- UINavigationController -> UITabBarController(NO)
同样是苹果官方提供的container view controller,为什么会有这个区别呢?
*************************************************************************************************************************
再次声明以下原因仅为个人猜想:
鉴于使用习惯和API设计考虑
80%-90%的app是以UITabBarController为根控制器,UINavigationController作为其中的tab,故关系1为YES,api设计上我们看下头文件,tabBarController/navigationController通过扩展为UIViewContoller添加属性,如果关系2 为 YES,以下头文件可看出,会导致tabBarController不知道指向哪一个。
我们平时工作中关系1我们一直用,即一般都会为UITabBarController添加几个UINavigationController,那关系1为YES我们可以理解,那这对关系2有什么影响呢,我吃肉也不代表我不吃素啊?先看下两个类的头文件UITabBarController.h@interface UIViewController (UITabBarControllerItem)@property(nullable, nonatomic, readonly, strong) UITabBarController *tabBarController; // If the view controller has a tab bar controller as its ancestor, return it. Returns nil otherwise.@end
UINavigationController.h@interface UIViewController (UINavigationControllerItem)@property(nullable, nonatomic,readonly,strong) UINavigationController *navigationController; // If this view controller has been pushed onto a navigation controller, return it.@end
头文件中可看出任何UIViewController都可以直接获取tabBarController或navigationController。假设以上关系 2 为 YES,如果界面结构如下:UITabBarController---->UINavigationController---->UITabBarController那么属性tabBarController为哪一个UITabBarController?
*************************************************************************************************************************
关于使用container view controller:
- 自定义的container view controller当不作为根控制器时,最好不要添加系统定义的可整屏切换的container view controller作为子视图,如UITabBarController/UINavigationController,可以添加局部切换的container view controller,如UIPageViewController。
- 自定义container view controller作为根控制器时,其它container view controller最好不要再添加此container view controller作为子视图。
自定义的类似UITabBarController的container view controller只允许添加非container view controller的UIViewController,除非作为root view controller。自定义的类似UINavigationController的container view controller不允许添加类似UITabBarController的container view controller。
PS:欢迎大家一起讨论,多多指教。
0 0
- UINavigationController方法pushViewController:参数不能传递UITabBarController原因猜想
- UINavigationController,UITabBarController
- UINavigationController, UITabBarController
- UINavigationController+UITabBarController
- UINavigationController、UITabBarController
- UINavigationController 的 pushViewController不起作用
- 方法之间参数传递获取不到原因
- UITabBarController UINavigationController 相结合代码
- UITabBarController UINavigationController 相结合代码
- UINavigationController与UITabBarController
- UITabBarController UINavigationController 相结合代码
- UINavigationController与UITabBarController
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用
- UINavigationController和UITabBarController合用。
- UINavigationController与UITabBarController
- UITabBarController inside a UINavigationController
- 隐藏UINavigationController和UITabBarController
- java web 编解码
- strcpy 不能用 unsigned char[]
- Resource Shrinking去掉无用的资源
- B2C电子商务系统研发——商品SKU分析和设计(一)
- c++中格式化输出。十六进制浮点数0x p输出问题
- UINavigationController方法pushViewController:参数不能传递UITabBarController原因猜想
- node 单元测试实践
- B2C电子商务系统研发——商品SKU分析和设计(二)
- 常用的免费的开源软件
- HDU 1023.Train Problem II【大卡特兰数】【9月25】
- vim插件之AutoComplPop和OmniCppComplete的安装和使用
- Light oj 1140 - How Many Zeroes?(数位dp)
- 十佳Web开发资源
- android点击屏幕空白处隐藏软键盘