Monday, June 10, 2013

UITabBarController moreNavigationController example in Objective C (iOS).


UITabBarController moreNavigationController

The view controller that manages the More navigation interface. (read-only)

@property(nonatomic, readonly) UINavigationController *moreNavigationController

Discussion of [UITabBarController moreNavigationController]
This property always contains a valid More navigation controller, even if a More button is not displayed on the screen. You can use the value of this property to select the More navigation controller in the tab bar interface or to compare it against the currently selected view controller.[UITabBarController moreNavigationController]

Do not add the object stored in this property to your tab bar interface manually. The More controller is displayed automatically by the tab bar controller as it is needed. You must also not look for the More navigation controller in the array of view controllers stored in the viewControllers property. The tab bar controller does not include the More navigation controller in that array of objects.

UITabBarController moreNavigationController example.
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!
}

Example of [UITabBarController moreNavigationController].
int index = tabBarController.selectedIndex;
if (tabBarController.selectedViewController ==
    tabBarController.moreNavigationController) {
    index = -1;  //assign some placeholder index for the "More" controller
}

UITabBarController moreNavigationController example.
@interface MyDelegate : NSObject <UITabBarControllerDelegate, UINavigationControllerDelegate>
{
}
Wherever you are assigning your class as delegate, do this:

- (void) assignDelegate:(MyDelegate)myDelegate toTabBarController:(UITabBarController*)tabBarController
{
  tabBarController.delegate = myDelegate;
  tabBarController.moreNavigationController.delegate = myDelegate;
}
And finally, in your delegate class add this method:

- (void) navigationController:(UINavigationController*)navigationController didShowViewController:(UIViewController*)viewController animated:(BOOL)animated
{
     // add code to handle the event
}

End of UITabBarController moreNavigationController example article.