Popping to a specific viewcontroller in a navigation stack

后端 未结 4 1605
Happy的楠姐
Happy的楠姐 2021-02-10 07:47

I have a come across a piece of code to pop to a specific viewcontroller in a navigation stack as below

for (UIViewController* viewController in self.navigationC         


        
4条回答
  •  [愿得一人]
    2021-02-10 07:55

    - (void) RetunToSpecificViewController{
    
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:[AnOldViewController class]]) { 
            //Do not forget to import AnOldViewController.h
    
                [self.navigationController popToViewController:controller
                                                  animated:YES];
                break;
            }
        }
    

    On Swift

    func RetunToSpecificViewController()
    {
        let viewControllers: [UIViewController] =  self.navigationController!.viewControllers as [UIViewController]
      self.navigationController!.popToViewController(viewControllers[viewControllers.count
            - 5], animated: true)
    }
    

    We have write a better tutorial on that , You can check https://appengineer.in/2014/03/13/pop-to-specific-view-controller-in-ios/

提交回复
热议问题