How to check viewcontroller is added in stack or not

后端 未结 10 784
北恋
北恋 2020-12-28 08:50

I have two view controllers. I have navigated from one view to another view by press the button to using below code.

 *let secondViewController = self.storyb         


        
10条回答
  •  不知归路
    2020-12-28 09:17

    You can check with below code

    Objective - C

    NSArray * controllers = [self.navigationController viewControllers];
    
        for (int i = 0; i < [controllers count]; i++){
    
            UIViewController * controllerTest = [controllers objectAtIndex:i];
    
            if([controllerTest isKindOfClass:[YourController class]]){
                NSLog(@"Class is available");
            }
    
        }
    

    Swift 3.0

    if let viewControllers = self.navigationController?.viewControllers {
                for viewController in viewControllers {
                    // some process
                    if viewController.isKindOfClass(YourController) {
                        print("Class is available")
                    }
                } 
            }
    

提交回复
热议问题