我正面临一个小问题。众所周知,如果您有超过5个选项卡,iOS将添加“更多”按钮,并使用“编辑”按钮在“更多”视图中显示其他条形项。由于某些原因,我想删除此按钮。我尝试了下面的方法,不知何故,它不起作用。
tabBarController.moreNavigationController.navigationItem.rightBarButtonItem = nil;
谁能帮我吗?谢谢。
tabBarController.navigationItem.rightBarButtonItem = nil;
希望它会有所帮助。
请在viewDidLoad
中添加导航代表。
self.navigationController.delegate = self;
首先,设置moreNavigationController的委托。
moreNavigationController.delegate = self
然后,您可以更改此委托方法中的导航项:
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
// remove edit button in 'more' table view
navigationController.navigationBar.topItem?.rightBarButtonItem = nil
}
您可以随时隐藏它,然后像这样禁用它:
self.tabBarController?.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.clear
self.tabBarController?.moreNavigationController.navigationBar.topItem?.rightBarButtonItem?.isEnabled = false
将UIColor更改为清除使其不可见,然后通过禁用其功能,使其完全无法使用,同时使其不可见。