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

前端 未结 16 967
借酒劲吻你
借酒劲吻你 2020-12-02 11:30

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 a

相关标签:
16条回答
  • 2020-12-02 12:20

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

    tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
    
    0 讨论(0)
  • 2020-12-02 12:22

    Simply add a line of code in life cycle method i.e. application did finish launching:

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    { 
        tabBarController.customizableViewControllers=nil;
    
    }
    
    0 讨论(0)
  • 2020-12-02 12:23

    An iPhone 6 Plus will allow more buttons on the tab bar in landscape mode than in portrait. Unfortunately this means it resets the customizableViewControllers array whenever the device is rotated, and none of the answers here worked for me.

    I already had my own UITabBarController subclass and overriding the setter and getter methods for customizableViewControllers was the only reliable way to remove the Edit button from the More screen:

    - (NSArray *)customizableViewControllers
    {
        return nil;
    }
    
    - (void)setCustomizableViewControllers:(NSArray*)controllers
    {
        //do nothing
    }
    
    0 讨论(0)
  • 2020-12-02 12:23

    Aleks N's answer works, but I'd like to modify a little bit

    - (void)navigationController:(UINavigationController *)navigationController
          willShowViewController:(UIViewController *)viewController
                        animated:(BOOL)animated
    {
        if (navigationController.viewControllers.count == 1)
        {
            UINavigationBar *morenavbar = navigationController.navigationBar;
            UINavigationItem *morenavitem = morenavbar.topItem;
            /* We don't need Edit button in More screen. */
            morenavitem.rightBarButtonItem = nil;
        }
    }
    

    Since this delegate method is called every time when a view controller is pushed or popped on this view stack. When we are pushing other views onto this "More" view controller, we don't want to do this.

    0 讨论(0)
提交回复
热议问题