Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the edit button that appears in the more section of a UITabBarController?

In my application (based on the Tab bar application XCode template) I use a UITabBarController to display a list of different sections of the application that the user can access.

By default, the UITabBarController displays a 'More' button in the tab bar when there are more than 5 items. Also, it allows the user to select the items that he want to be visible in the tab bar.

Currently I can't implement saving and loading the state of the tab bar controller, so I want to disable the 'Edit' button.

Is there any way to disable/hide the 'Edit' bar button that appears on the 'More' navigation controller of UITabBarController?

I tried:

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem = nil;

and

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem.enabled = NO;

but they don't seem to work.

like image 973
Panagiotis Korros Avatar asked May 05 '09 14:05

Panagiotis Korros


2 Answers

Become a delegate of moreNavigationController (it is a UINavigationController) and add this:

- (void)navigationController:(UINavigationController *)navigationController
        willShowViewController:(UIViewController *)viewController
        animated:(BOOL)animated {

    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    /* We don't need Edit button in More screen. */
    morenavitem.rightBarButtonItem = nil;
}

Now it won't appear. The key thing to consider is that Edit button appears not after controller creation, but before displaying the view, and we should sit silently till that moment and then, when the controller is going to display the screen, we will knock the button out so that it won't have a chance to create it again. :)

like image 172
Aleks N. Avatar answered Oct 21 '22 14:10

Aleks N.


customizableViewControllers is an array; set it to the empty array to disable all editing.

tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
like image 25
Ian Terrell Avatar answered Oct 21 '22 16:10

Ian Terrell