Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing UITabBarController's moreNavigationController

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?

like image 858
Mihai Damian Avatar asked Dec 08 '10 15:12

Mihai Damian


2 Answers

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!
}
like image 197
Bomber Avatar answered Oct 01 '22 02:10

Bomber


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.

like image 33
Alkimake Avatar answered Oct 01 '22 03:10

Alkimake