Pop 到 指定页面 && DismissTo 到 指定页面

DismissTo 到 指定页面

DismissTo 到 上一级的上一级页面

- (IBAction)backRootBtn:(UIButton *)sender {
    UIViewController * tempVCtrl = self.presentingViewController;
    if(tempVCtrl.presentingViewController) {
        tempVCtrl = tempVCtrl.presentingViewController;
    }
    [tempVCtrl dismissViewControllerAnimated: YES completion: nil ];
    
}

DismissTo 到 Root页面

- (IBAction)backRootBtn:(UIButton *)sender {
    UIViewController * tempVCtrl = self.presentingViewController;
    while (tempVCtrl.presentingViewController) {
        tempVCtrl = tempVCtrl.presentingViewController;
    }
    [tempVCtrl dismissViewControllerAnimated: YES completion: nil ];
    
}



dissmissViewController到跟控制器

Pop 到 指定页面


A
你初始化一个视图控制器干嘛啊?占不占内存啊?你也没用啊。


int index = (int)[[self.navigationController viewControllers]indexOfObject:self];
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -2)] animated:YES];


B

HomeViewController *homeVC = [[HomeViewController alloc] init];
                  UIViewController *target = nil;
                  for (UIViewController * controller in self.navigationController.viewControllers) { //遍历
                      if ([controller isKindOfClass:[homeVC class]]) { //这里判断是否为你想要跳转的页面
                          target = controller;
                      }
                  }
                  if (target) {
                      [self.navigationController popToViewController:target animated:YES]; //跳转  
                  }



那如何获取自己的viewController处于第几级啊?这个是不固定的????

  for (UIViewController* v in [UIApplication sharedApplication].windows) {
        NSLog(@"%@",[v class]);
    }

1、自己记住
2、遍历viewControllers

你可能感兴趣的:(Pop 到 指定页面 && DismissTo 到 指定页面)