1

我通过从moreNavigationController.

我找不到错误,它一定是一个简单的错误。

TabBarViewController我在 IB 中创建了一些将它与我的TabBarViewController.

这是代码:

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

编辑按钮仍然存在:/

4

5 回答 5

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

这应该有效,它对我有用。

于 2013-05-23T13:03:57.380 回答
2

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

tabBarController.customizableViewControllers = [];  
于 2015-10-20T08:16:54.940 回答
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

于 2015-02-12T03:32:29.060 回答
0

After reading all of the above and converting it to Swift 3 I noticed that when one of the view controllers which was shown after selecting the More... tab was a navigationcontroller and had a rightBarButton item, that item was removed as well! 由于这是不希望的,我想出了以下解决方案:

//
//  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 中显示的图标为绿色,而不是标准的蓝色色调,因为我也在标签栏上使用了绿色图标。

于 2017-08-24T12:21:59.937 回答
0

这对我有用

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    tabBarController.customizableViewControllers?.removeAll()
}
于 2019-06-15T16:55:39.860 回答