我在iOS应用程序上工作,我想检查特定ViewController是否在导航堆栈中出现多次。

最佳答案

self.navigationController.viewControllers返回堆栈中的所有视图控制器。喜欢

@interface ViewController () {
    // create the one global int for get the count of VC.
    int myVar;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    myVar = 0;
    for (UIViewController *vc in self.navigationController.viewControllers) {
        // check your VC is available or not in using isKindOfClass
        if ([vc isKindOfClass:[ViewController class]]) {
            myVar +=  1;
        }
    }

    if (myVar > 1){
        // available
    }
}

关于ios - 检查特定ViewController是否在导航堆栈中不止一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50816583/

10-10 14:27