拦截所有push进来的控制器

来源:互联网 发布:蚁群算法原理及优缺点 编辑:程序博客网 时间:2024/06/03 17:36
/**
 * 
拦截所有push进来的控制器,
 *
 *  @param viewController
即将push进来的控制器
 */

-(
void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated {
   
   
if (self.viewControllers.count> 0) { // 如果不是根控制器

        viewController.
hidesBottomBarWhenPushed= YES;
       
// 设置左侧返回按钮
        viewController.
navigationItem.leftBarButtonItem= [UIBarButtonItemitemWithTarget:selfaction:@selector(backBarBtnAction:)image:@"navigationbar_back"highImage:@"navigationbar_back_highlighted"];
       
       
// 设置右侧按钮
        viewController.
navigationItem.rightBarButtonItem= [UIBarButtonItemitemWithTarget:selfaction:@selector(rightBtnAction:)image:@"navigationbar_more"highImage:@"navigationbar_more_highlighted"];
    }
    [
superpushViewController:viewControlleranimated:animated];
}
// pop上一控制器按钮
- (
void)backBarBtnAction:(UIButton*)button {
    button.
selected= !button.selected;
#warning这里要使用self,不能使用self.navigationController
    // 因为self.navigationController是空的,因为self本来就是导航控制器
    [
selfpopViewControllerAnimated:YES];
   
}
0 0