问题
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:
moreViewController
is controlled byUIKit
. Externally, it is very hard to customize some views and control them directly. There will be unpredictable methods and layer definitions inmoreViewController
. It can't be basicUITableViewController
. I think customizing classes that have delegates is more efficient.If you customize
moreViewController
, you may have to release a new version of your app each time Apple releases new iOS. The developers ofmoreViewController
at Apple may change entire class to something else. So your application will stop responding.My own class, my own home. I can do whatever I want.
来源:https://stackoverflow.com/questions/4389229/customizing-uitabbarcontrollers-morenavigationcontroller