iOS实战之导航栏

#1、隐藏和显示导航栏方法一:(简单粗暴)

- (void)viewWillAppear:(BOOL)animated { 
  [super viewWillAppear:animated]; 
  [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated { 
  [super viewWillDisappear:animated]; 
  [self.navigationController setNavigationBarHidden:NO animated:YES];
}

方法二:(使用代理)

//UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
  BOOL isHiddenNavBar = [viewController isKindOfClass:[self class]]; 
  [self.navigationController setNavigationBarHidden:isVC animated:YES];
}

#2、自定义UINavigationController返回按钮

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    ViewController *vc = [ViewController new];
    UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:vc];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"返回";
    vc.navigationItem.backBarButtonItem = backItem;
    self.window.rootViewController = navC;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
}