/**
* 拦截所有push进来的控制器,
*
* @param viewController 即将push进来的控制器
*/
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count > 0) { // 如果不是根控制器
viewController.hidesBottomBarWhenPushed = YES;
// 设置左侧返回按钮
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(backBarBtnAction:) image:@"navigationbar_back" highImage:@"navigationbar_back_highlighted"];
// 设置右侧按钮
viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBtnAction:) image:@"navigationbar_more" highImage:@"navigationbar_more_highlighted"];
}
[super pushViewController:viewController animated:animated];
}
// pop上一控制器按钮
- (void)backBarBtnAction:(UIButton *)button {
button.selected = !button.selected;
#warning 这里要使用self,不能使用self.navigationController
// 因为self.navigationController 是空的,因为self本来就是导航控制器
[self popViewControllerAnimated:YES];
* 拦截所有push进来的控制器,
*
* @param viewController 即将push进来的控制器
*/
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count > 0) { // 如果不是根控制器
viewController.hidesBottomBarWhenPushed = YES;
// 设置左侧返回按钮
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(backBarBtnAction:) image:@"navigationbar_back" highImage:@"navigationbar_back_highlighted"];
// 设置右侧按钮
viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBtnAction:) image:@"navigationbar_more" highImage:@"navigationbar_more_highlighted"];
}
[super pushViewController:viewController animated:animated];
}
// pop上一控制器按钮
- (void)backBarBtnAction:(UIButton *)button {
button.selected = !button.selected;
#warning 这里要使用self,不能使用self.navigationController
// 因为self.navigationController 是空的,因为self本来就是导航控制器
[self popViewControllerAnimated:YES];
}