检查特定ViewController是否在导航堆栈中不止一次

时间:2018-06-12 11:55:31

标签: ios objective-c iphone xcode

我正在研究iOS应用程序,我想在其中检查特定ViewController是否在导航堆栈中出现多次。

1 个答案:

答案 0 :(得分:1)

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
    }
}