从moreNavigationController中删除编辑按钮不起作用

时间:2013-05-23 12:33:19

标签: objective-c

通过从moreNavigationController删除编辑按钮,我遇到了一些问题。

我无法找到错误,它必须是一个简单的错误。

我创建了一些TabBarViewController在我的TabBarViewController

中将其连接到IB

以下是代码:

TabBarViewController.h

    #import <UIKit/UIKit.h>

@interface TabBarViewController : UITabBarController <UINavigationControllerDelegate, UITabBarControllerDelegate>


@end

TabBarViewController.m

#import "TabBarViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

     self.delegate = self;

   [self.moreNavigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];
    [self.moreNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.bg.png"] forBarMetrics:UIBarMetricsDefault];
    [self.moreNavigationController.navigationBar.topItem setRightBarButtonItem:nil];   

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

编辑按钮就在那里:/

5 个答案:

答案 0 :(得分:8)

您需要将navigationController委托设置为tabBarController。在TabBarViewController

的viewDidLoad方法中添加以下行
self.moreNavigationController.delegate = self;

使用UINavigationController navigationController:willShowViewController:animated:的委托方法隐藏barButtonItem

使用以下代码

- (void)navigationController:(UINavigationController *)navigationController
  willShowViewController:(UIViewController *)viewController
                animated:(BOOL)animated
{
    navigationController.navigationBar.topItem.rightBarButtonItem = Nil;
}

这应该有用,对我有用。

答案 1 :(得分:2)

有一个更漂亮的解决方案:

tabBarController.customizableViewControllers = [];  

答案 2 :(得分:0)

Prasad Devadiga谢谢你! 在我的TabBarViewController.m

#import "TabBarViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.moreNavigationController.delegate = self;
    navigationController:willShowViewController:animated:YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    navigationController.navigationBar.topItem.rightBarButtonItem = Nil;
}

@end

在我的TabBarViewController.h中 我插入此代码

#import <UIKit/UIKit.h>

@interface TabBarViewController : UITabBarController <UINavigationControllerDelegate, UITabBarControllerDelegate>

@end

这适用于IOS7

答案 3 :(得分:0)

在阅读了上述所有内容并将其转换为Swift 3之后,我注意到当选择More ...选项卡后显示的其中一个视图控制器是一个导航控制器并且有一个rightBarButton项目时,该项目也被删除了!由于不需要,我想出了以下解决方案:

//
//  CustomizedTabBarController.swift
//

import UIKit

class CustomizedTabBarController: UITabBarController, UINavigationControllerDelegate {

    var root : UIViewController?

    override func viewDidLoad() {
        super.viewDidLoad()

        root = self.moreNavigationController.topViewController

        // Make sure the icons have the proper tint color
        if let view = root?.view {
            view.tintColor = UIColor.green
        }

        self.moreNavigationController.delegate = self

    }

    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        // Only hide the rightBarButtonItem when this is the morenavigationcontroller
        if( viewController == root ){
            navigationController.navigationBar.topItem?.rightBarButtonItem = nil
        }
    }
}

作为额外的我还强制moreNavigationController中显示的图标为绿色而不是标准的蓝色tintcolor,因为我在tabbar上也使用了绿色图标。

答案 4 :(得分:0)

这对我有用

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    tabBarController.customizableViewControllers?.removeAll()
}