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

前端 未结 16 968
借酒劲吻你
借酒劲吻你 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:12

    I tried most of these solutions and was running into an issue where the edit button would return when rotating the device. The rotation would reset back to the first view controller, then when i returned to the more view controller, the edit button was there. The best solution was to become the UITabBarControllerDelegate and set the right bar button to nil anytime the more view controller became the selected view controller. This is working for iOS 11-12.

    final class DashboardController: UITabBarController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            delegate = self
        }
    }
    
    extension DashboardController: UITabBarControllerDelegate {
        func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
            if viewController == moreNavigationController {
                moreNavigationController.navigationBar.topItem?.rightBarButtonItem = nil
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-02 12:14
    tabBarController .customizableViewControllers = nil;
    
    0 讨论(0)
  • 2020-12-02 12:15

    If you use NavigationController as your 1st ViewController and press one of the button to enter UITabBarController. Then apart from adding the code below,

    - (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;
    }
    

    you need to add this "if statement" to avoid the edit button shows up when you first click the 5th ViewControllers and above.

    if (self.selectedIndex >= 4) 
    {
        self.customizableViewControllers = nil;
    }
    
    0 讨论(0)
  • 2020-12-02 12:19

    At the ones working with Xcode greater than 4.0 (I'm working on Xcode 4.2 for Snow Leopard):

    Check at first where do you change the array of views the last time. I think it doesn't matter in which method you set your customizableView-Array to nil. Apples description says:

    Important: Adding or removing view controllers in your tab bar interface also resets the array of customizable view controllers to the default value, allowing all view controllers to be customized again. Therefore, if you make modifications to the viewControllers property (either directly or by calling the setViewControllers:animated: method) and still want to limit the customizable view controllers, you must also update the array of objects in the customizableViewControllers property.

    It worked for me, so please try it out. I found this description here: link to the description on developer.apple.com at chapter "Preventing the Customization of Tabs".

    0 讨论(0)
  • 2020-12-02 12:19

    The only solution that worked for me

    self.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.title = ""
    self.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.isEnabled = false
    
    0 讨论(0)
  • 2020-12-02 12:20

    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. :)

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