我正在开发 iOS 应用程序,我想检查特定 ViewController 是否在导航堆栈中出现多次。
最佳答案
self.navigationController.viewControllers
返回堆栈中的所有 View Controller 。喜欢
@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/