iphone - 如何禁用出现在 UITabBarController 的“更多”部分中的编辑按钮?

标签 iphone uitabbarcontroller

在我的应用程序中(基于选项卡栏应用程序 XCode 模板),我使用 UITabBarController 来显示用户可以访问的应用程序不同部分的列表。

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

目前我无法实现标签栏 Controller 状态的保存和加载,所以我想禁用“编辑”按钮。

有什么方法可以禁用/隐藏 UITabBarController 的“更多”导航 Controller 上显示的“编辑”栏按钮吗?

我尝试过:

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

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

但它们似乎不起作用。

最佳答案

成为 moreNavigationController 的委托(delegate)(它是一个 UINavigationController)并添加以下内容:

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

现在不会出现了。需要考虑的关键是,编辑按钮不是在 Controller 创建之后出现,而是在显示 View 之前出现,我们应该静静地坐着直到那一刻,然后,当 Controller 要显示屏幕时,我们将按钮敲出,以便它不会有机会再次创建它。 :)

关于iphone - 如何禁用出现在 UITabBarController 的“更多”部分中的编辑按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/825066/

相关文章:

ios - Xcode 错误 : calling -display has no effect

ios - 将数据从 ViewController 传递到 TabBarController

iphone - UITabBar 模态视图 Controller

ios - UITabBar 在顶部还是其他?

ios - 切换到 UITabBarController 内的分段控件索引

iphone - WPF/C# : 'Slide to Unlock' feature from iPhone

iphone - 如何将普通 View 颜色更改为棕褐色?

android - 根据屏幕方向隐藏 Ionic 框架标题

ios - 无法在 bundle 中找到名为 'Main' 的 Storyboard,Xcode 7

ios - 应用程序看起来像主从行为就像标签栏 Controller