简体   繁体   English

自定义UITabBarController的moreNavigationController

[英]Customizing UITabBarController's moreNavigationController

I'm in the process of customizing the 'More' view in my app's UITabBarController. 我正在我的应用程序的UITabBarController中自定义“更多”视图。

From what I see in the docs there is precious little support for customizing it. 从我在文档中看到的内容来看,很少有人支持自定义它。 There is only a read-only property of the UITabBarController called 'moreNavigationController' that points to a UINavigationController. UITabBarController只有一个名为'moreNavigationController'的只读属性,它指向UINavigationController。

This allows us at least to customize it's UINavigationBar. 这使我们至少可以自定义它的UINavigationBar。 Customizing the table view it presents in the first view controller is a little trickier. 自定义它在第一个视图控制器中显示的表视图有点棘手。

On other questions here on SO and elsewhere, I've seen that all talk revolves around messing with the internal structure of the moreNavigationController (for example observing that the first view controller in the stack is a UITableViewController, swapping out it's data controller, etc.). 关于SO和其他地方的其他问题,我已经看到所有的讨论围绕着搞乱moreNavigationController的内部结构(例如,观察堆栈中的第一个视图控制器是UITableViewController,交换它的数据控制器等等)。 )。 Problem is all these methods make assumptions about how undocumented code in the API behaves, assumptions that are hardly future-proof. 问题是所有这些方法都假设API中未记录的代码如何表现,这些假设很难面向未来。

The only alternative I see here is to roll my own custom "more controller" (optionally ditching the edit functionality to keep the implementation fairly simple) and using it as the fifth view controller in the tab. 我在这里看到的唯一选择是滚动我自己的自定义“更多控制器”(可选地放弃编辑功能以保持实现相当简单)并将其用作选项卡中的第五个视图控制器。 Of course care must be taken to assign the subsequent view controllers to the custom "more controller" not to the UITabBarController directly (subclassing the UITabBarController may be required to enforce this rule). 当然必须注意将后续视图控制器分配给自定义“更多控制器”而不是直接分配给UITabBarController(可能需要对UITabBarController进行子类化以强制执行此规则)。

Which approach would you choose? 你会选择哪种方法? What other solutions would you suggest? 你会建议其他什么解决方案?

I would choose to roll my own custom controller for 3 reasons: 我会选择推出自己的自定义控制器有三个原因:

  1. moreViewController is controlled by UIKit . moreViewControllerUIKit控制。 Externally, it is very hard to customize some views and control them directly. 在外部,很难自定义一些视图并直接控制它们。 There will be unpredictable methods and layer definitions in moreViewController . moreViewController会有不可预测的方法和图层定义。 It can't be basic UITableViewController . 它不能是基本的UITableViewController I think customizing classes that have delegates is more efficient. 我认为定制具有委托的类更有效。

  2. If you customize moreViewController , you may have to release a new version of your app each time Apple releases new iOS. 如果您自定义moreViewController ,则每次Apple发布新iOS时,您可能必须发布新版本的应用程序。 The developers of moreViewController at Apple may change entire class to something else. Apple的moreViewController的开发人员可能会将整个类更改为其他类。 So your application will stop responding. 所以你的应用程序将停止响应。

  3. My own class, my own home. 我自己的班级,我自己的家。 I can do whatever I want. 我可以做任何我想做的事。

UIViewController *tbMore = 
    ((UIViewController*)
    [self.moreNavigationController.viewControllers objectAtIndex:0]);

int nRows = [((UITableView *)tbMore.view) numberOfRowsInSection:0];

for (int i = 0; i < nRows; i++)
{
    UITableViewCell *c =
        [((UITableView *)tbMore.view)
        cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

    // Do any additional customization here!
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM