UINavigationController常用小技巧

UINavigationcontroller-push自动 hiddenBottomBar

项目中如果你的项目开始的时候 UITabBarController是用的UINavigationController ,每次 push 都要viewController.hidesBottomBarWhenPushed = YES;下面介绍一个方法,让你不需要这么麻烦:

1.自定义 XXNavigationController ,里面重写
pushViewController:viewController:animated:方法

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0)
    {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

2.在UITabBarControoler换掉UINavigationController即可
3.当然你也可以全局换掉,看个人喜好

pop回某一个具体的控制器

 NSArray *viewControllers = [[self navigationController] viewControllers];
                        for( int i=0;i<[viewControllers count];i++){
                            id obj=[viewControllers objectAtIndex:i];
                            if([obj isKindOfClass:[ExampleOneController class]]){
                                [[self navigationController] popToViewController:obj animated:YES];
                                
                            }

你可能感兴趣的:(UINavigationController常用小技巧)