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

Pan*_*ros 25 iphone uitabbarcontroller

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

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

目前我无法实现保存和加载标签栏控制器的状态,所以我想禁用"编辑"按钮.

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

我试过了:

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem = nil;
Run Code Online (Sandbox Code Playgroud)

tabBarController.moreNavigationController.navigationBar.topItem.rightBarButtonItem.enabled = NO;
Run Code Online (Sandbox Code Playgroud)

但他们似乎没有工作.

Ale*_* N. 59

成为moreNavigationController(它是一个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;
}
Run Code Online (Sandbox Code Playgroud)

现在它不会出现.要考虑的关键是编辑按钮不是在控制器创建之后,而是在显示视图之前出现,我们应该静静地坐到那一刻,然后,当控制器要显示屏幕时,我们将按下按钮以便它没有机会再创造它.:)

  • 我认为如果customizableViewControllers数组为空或者为零,那么当Edit按钮真的应该自动消失时,我们应该必须实现这样的黑客...但这不是Aleks的错,他的解决方案对我有用. (6认同)

Ian*_*ell 53

customizableViewControllers是一个数组; 将其设置为空数组以禁用所有编辑.

tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
Run Code Online (Sandbox Code Playgroud)


m4r*_*rkk 12

tabBarController .customizableViewControllers = nil;
Run Code Online (Sandbox Code Playgroud)


小智 6

我试过了,这是一个例子.

在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];

    //setting delegate to disable edit button in more.
    tabBarController.moreNavigationController.delegate = self;

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

删除"编辑"按钮

    - (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;
}
Run Code Online (Sandbox Code Playgroud)

在你的AppDelegate.h中

@interface TestAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate, UINavigationControllerDelegate>
Run Code Online (Sandbox Code Playgroud)

如我错了请纠正我.