导航控制返回到指定的页面

163 阅读1分钟

/** * 返回到指定页面 */

-(void)popToViewController:(Class )showController isShow:(BOOL)isshow {
    NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
    UIViewController *currentController = [navigationArray lastObject];
    for (NSInteger i = navigationArray.count-1 ;i >= 0 ;i--) {
        UIViewController *vc = [navigationArray objectAtIndex:i];
        if (![vc isKindOfClass:[showController class]]) {
            [navigationArray removeObject:vc];
        }
        else{
          //是否显示当前页面
         if (isshow) {
            [navigationArray addObject:currentController];
         }
        self.navigationController.viewControllers = navigationArray;
        return;
       }
     }
}