gpt4 book ai didi

ios - 检查特定 ViewController 是否多次出现在导航堆栈中

转载 作者:行者123 更新时间:2023-11-28 23:57:25 26 4
gpt4 key购买 nike

我正在开发 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com