如何禁用出现在UITabBarController的更多部分中的编辑按钮? [英] How to disable the edit button that appears in the more section of a UITabBarController?

查看:98
本文介绍了如何禁用出现在UITabBarController的更多部分中的编辑按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中(基于Tab栏应用程序XCode模板)我使用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.

默认情况下,当有超过5个项目时,UITabBarController在选项卡栏中显示更多按钮。此外,它允许用户选择他希望在标签栏中显示的项目。

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.

有没有办法禁用/隐藏更多上显示的编辑栏按钮UITabBarController的导航控制器?

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

我试过:

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

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

但它们似乎不起作用。

推荐答案

成为 moreNavigationController 的委托(它是一个UINavigationController)并添加:

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

这篇关于如何禁用出现在UITabBarController的更多部分中的编辑按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆