如何获得UIMoreListController(一个私有框架类)的子视图控制器? [英] How to obtain child view controllers of UIMoreListController (a private framework class)?

查看:661
本文介绍了如何获得UIMoreListController(一个私有框架类)的子视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,如果有一个合法的API可以获得作为 UIMoreListController 的子视图控制器? (UIMoreListController是UIMoreNavigationController视图栈顶部的子UIMoreNavigationController是 moreNavigationController 属性指向的对象 UITabBarController 。)



换句话说,如果我有一个UITabBarController,并且我设置了一个六个视图控制器的数组,这实际上是视图的层次结构,而不是视图控制器,但使用这些标识符更有意义):

  + UITabBarController< - 有五个标签
| --- view controller< - 这些是我自己的视图控制器
| ---视图控制器
| ---视图控制器
| --- view controller
| - + UIMoreNavigationController< - 第五个标签的根视图控制器
| - + UIMoreListController < - 第五个标签上显示的基于表的视图
| --- view controller< - 这些是我自己的视图控制器
| ---视图控制器


$ b b

这样做的一种方法是简单地从UITabBarController的 viewControllers 属性中获取视图控制器,检查是否有超过5个,并返回所有视图控制器从索引5到 N - 1 如果有超过5.(如果有少于5,则视图控制器将是UIMoreNavigationController的子节点。)<然而,我想避免硬编码任何假设关于视图控制器的数量UITabBarController将显示之前列出剩余的控制器在 moreNavigationController 。苹果可以改变这个数字在未来。但我不能在UITabBarController或UINavigationController上找到任何API来访问这些孩子,而UIMoreNavigationController不是一个公共类,所以我不能依赖任何暴露在该类上的方法。

解决方案

我还没有找到一个真正的API来完成这个。然而,它可以不做假设基于检查 UIUserInterfaceIdiom ,并假设最多5或8个选项卡。这是一种丑陋,很简单:


  1. 获取标签栏中的项目数。 如果有这样的标签栏项,UITabBarController.tabBar.items 将包括 moreNavigationController 的标签栏项。

  2. 计算UITabBarController中视图控制器的数量。如果UITabBarController中的视图控制器比标签栏项目多,则最后一个选项卡栏项目代表 moreNavigationController

  3. 因此,将标签栏项目的数量减1(以考虑 moreNavigationController ),这是的第一个孩子的索引, moreNavigationController c> $ 内。

,在代码中:

  NSUInteger tabCount = [tabBarController.tabBar.items count]; 
NSUInteger vcCount = [tabBarController.viewControllers count];
NSUInteger idx =(vcCount> tabCount)? tabCount - 1:0;
NSIndexSet * is = [NSIndexSet indexSetWithRange:NSMakeRange(idx,vcCount - idx)];
NSArray * moreControllers = [tabBarController.viewControllers objectsAtIndexes:is];


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.

解决方案

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:

  1. Obtain the number of items in the tab bar. UITabBarController.tabBar.items will include the tab bar item for the moreNavigationController, if there is such a tab bar item.
  2. Count the number of view controllers in the UITabBarController. If there are more view controllers in the UITabBarController than there are tab bar items, then the last tab bar item represents the moreNavigationController.
  3. Therefore, decrement the count of the number of tab bar items by one (to account for the moreNavigationController) and that's the index of the first child of the moreNavigationController within UITabBarController.viewControllers.

Or, in code:

NSUInteger tabCount = [tabBarController.tabBar.items count];
NSUInteger vcCount = [tabBarController.viewControllers count];
NSUInteger idx = (vcCount > tabCount) ? tabCount - 1 : 0;
NSIndexSet *is = [NSIndexSet indexSetWithRange:NSMakeRange(idx, vcCount - idx)];
NSArray *moreControllers = [tabBarController.viewControllers objectsAtIndexes:is];

这篇关于如何获得UIMoreListController(一个私有框架类)的子视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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