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

前端 未结 16 1044
借酒劲吻你
借酒劲吻你 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
            }
        }
    }
    

提交回复
热议问题