Customizing UITabBarController's moreNavigationController

[亡魂溺海] 提交于 2019-12-21 12:31:36

问题


I'm in the process of customizing the 'More' view in my app's 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.

This allows us at least to customize it's 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.). Problem is all these methods make assumptions about how undocumented code in the API behaves, assumptions that are hardly future-proof.

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).

Which approach would you choose? What other solutions would you suggest?


回答1:


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!
}



回答2:


I would choose to roll my own custom controller for 3 reasons:

  1. moreViewController is controlled by UIKit. Externally, it is very hard to customize some views and control them directly. There will be unpredictable methods and layer definitions in moreViewController. It can't be basic 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. The developers of moreViewController at Apple may change entire class to something else. So your application will stop responding.

  3. My own class, my own home. I can do whatever I want.



来源:https://stackoverflow.com/questions/4389229/customizing-uitabbarcontrollers-morenavigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!