解决方法如下:
实现UINavigationControllerDelegate的- navigationController:willShowViewController:animated: 方法
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationController.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UINavigationControllerDelegate -
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
//判断当前viewController 是否是需要隐藏导航栏,如果是需要隐藏的VC isViewController将为YES 反之 NO 将会显示出导航栏
//其中viewController为navigationController: willShowViewController: animated: 方法里的参数viewController
//[ViewController class]中的ViewController为具体需要隐藏导航栏的类名
BOOL isViewController = [viewController isKindOfClass:[ViewController class]];
[navigationController setNavigationBarHidden:isViewController animated:true];
}
@end