如何获取UIMoreListController(私有框架类)的子视图控制器?
我很好奇是否有一个合法的 API 可以用来获取 UIMoreListController 的子视图控制器? (UIMoreListController 是 UIMoreNavigationController 视图堆栈顶部的子级。UIMoreNavigationController 是 UITabBarController
的 moreNavigationController
属性所指向的对象。)
换句话说,如果我有一个 UITabBarController 并在其上设置了一个由六个视图控制器组成的数组,视图层次结构实际上看起来像这样(它实际上是视图层次结构,不是视图控制器,而是使用这些标识符更有意义):
+ UITabBarController <-- has five tabs
|--- view controller <-- these are my own view controllers
|--- view controller
|--- view controller
|--- view controller
|--+ UIMoreNavigationController <-- root view controller of fifth tab
|--+ UIMoreListController <-- table-based view shown on fifth tab
|--- view controller <-- these are my own view controllers
|--- view controller
一种方法是简单地从 UITabBarController 的 viewControllers 属性获取视图控制器,检查是否超过 5 个,然后将索引 5 中的所有视图控制器返回到N - 1
如果超过 5 个。(如果少于 5 个,则没有视图控制器将成为 UIMoreNavigationController 的子级。)
但是,我想避免对任何假设进行硬编码在 moreNavigationController
中列出剩余控制器之前,UITabBarController 将显示的视图控制器的数量。苹果将来可能会改变这个数字。但我在 UITabBarController 或 UINavigationController 上找不到任何用于访问这些子项的 API,并且 UIMoreNavigationController 不是公共类,因此我不能依赖该类上公开的任何方法。
I'm curious if there is a legitimate API with which to obtain the view controllers that are children of a UIMoreListController
? (The UIMoreListController is the child at the top of the UIMoreNavigationController's view stack. The UIMoreNavigationController is the object pointed to by the moreNavigationController
property of a UITabBarController
.)
In other words, if I have a UITabBarController and I set an array of six view controllers on it, the view hierarchy will actually look like this (it's actually a hierarchy of views, not view controllers, but using these identifiers make more sense):
+ UITabBarController <-- has five tabs
|--- view controller <-- these are my own view controllers
|--- view controller
|--- view controller
|--- view controller
|--+ UIMoreNavigationController <-- root view controller of fifth tab
|--+ UIMoreListController <-- table-based view shown on fifth tab
|--- view controller <-- these are my own view controllers
|--- view controller
One way to do this is to simply get the view controllers from the UITabBarController's viewControllers
property, check to see if there are more than 5, and return all the view controllers from index 5 to N - 1
if there are more than 5. (If there are less than 5, then no view controllers will be children of the UIMoreNavigationController.)
However, I'd like to avoid hardcoding any assumptions about the number of view controllers that a UITabBarController will display before listing the remaining controllers in the moreNavigationController
. Apple could change that number in the future. But I can't find any API on either UITabBarController or on UINavigationController with which to access these children, and UIMoreNavigationController is not a public class so I can't rely on any methods exposed on that class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有找到真正的 API 来完成这个任务。但是,无需基于检查 UIUserInterfaceIdiom 并假设最多 5 或 8 个选项卡进行假设即可完成此操作。它有点丑陋,也很简单:
UITabBarController.tabBar.items
将包含moreNavigationController
的选项卡栏项目(如果有这样的选项卡栏项目)。moreNavigationController
。moreNavigationController
),这就是moreNavigationController
中第一个子项的索引UITabBarController.viewControllers。或者,在代码中:
I still haven't found a real API for accomplishing this. However, it can be done without making assumptions based on checking the
UIUserInterfaceIdiom
and assuming a max of 5 or 8 tabs. It's kind of ugly, kind of simple:UITabBarController.tabBar.items
will include the tab bar item for themoreNavigationController
, if there is such a tab bar item.moreNavigationController
.moreNavigationController
) and that's the index of the first child of themoreNavigationController
withinUITabBarController.viewControllers
.Or, in code: