Objective c 从moreNavigationController中删除编辑按钮不工作

Objective c 从moreNavigationController中删除编辑按钮不工作,objective-c,Objective C,我从moreNavigationController中删除编辑按钮时遇到了一些问题 我找不到错误,一定是个简单的错误 我创建了一些TabBarViewController,将其与我的TabBarViewController连接在IB中 代码如下: TabBarViewController.h: 编辑按钮仍然在那里:/您需要将navigationController委托设置为tabBarController。在TabBarViewController类的viewDidLoad方法中添加以下行 使用

我从moreNavigationController中删除编辑按钮时遇到了一些问题

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

我创建了一些TabBarViewController,将其与我的TabBarViewController连接在IB中

代码如下:

TabBarViewController.h:


编辑按钮仍然在那里:/

您需要将navigationController委托设置为tabBarController。在TabBarViewController类的viewDidLoad方法中添加以下行

使用UINavigationController导航controller:willShowViewController:animated:的委托方法隐藏barButtonItem

使用以下代码


这应该行得通,对我也行。

您需要将navigationController委托设置为您的tabBarController。在TabBarViewController类的viewDidLoad方法中添加以下行

使用UINavigationController导航controller:willShowViewController:animated:的委托方法隐藏barButtonItem

使用以下代码


这应该行得通,对我也行。

普拉萨德·德瓦迪加,谢谢你! 在我的选项卡BarViewController.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
在我的选项卡BarViewController.h中 我插入此代码

#import <UIKit/UIKit.h>

@interface TabBarViewController : UITabBarController <UINavigationControllerDelegate, UITabBarControllerDelegate>

@end

这是在IOS7上工作的Prasad Devadiga谢谢你! 在我的选项卡BarViewController.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
在我的选项卡BarViewController.h中 我插入此代码

#import <UIKit/UIKit.h>

@interface TabBarViewController : UITabBarController <UINavigationControllerDelegate, UITabBarControllerDelegate>

@end

这是在IOS7上运行的

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

tabBarController.customizableViewControllers = [];  
//
//  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
        }
    }
}

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

tabBarController.customizableViewControllers = [];  
//
//  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
        }
    }
}

在阅读了以上所有内容并将其转换为Swift 3后,我注意到当选择“更多”后显示的一个视图控制器。。。tab是一个navigationcontroller,有一个rightBarButton项,该项也被删除了!由于这是不可取的,我提出了以下解决方案:

tabBarController.customizableViewControllers = [];  
//
//  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中显示的图标为绿色,而不是标准的蓝色,因为我在选项卡栏上也使用了绿色图标

阅读完以上所有内容并将其转换为Swift 3后,我注意到当选择“更多”后显示的一个视图控制器。。。tab是一个navigationcontroller,有一个rightBarButton项,该项也被删除了!由于这是不可取的,我提出了以下解决方案:

tabBarController.customizableViewControllers = [];  
//
//  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中显示的图标为绿色,而不是标准的蓝色,因为我在选项卡栏上也使用了绿色图标

这对我有用

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    tabBarController.customizableViewControllers?.removeAll()
}
这对我有用

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

你在哪个版本的iOS上测试过这个?我试过了,但它在10.2上不起作用。您在哪个版本的iOS上测试过它?我试过了,但在10.2上不起作用