我正在研究iOS应用程序,我想在其中检查特定ViewController是否在导航堆栈中出现多次。
答案 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
}
}