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

标签 ios objective-c iphone xcode

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

相关文章:

ios - 在 Xcode 描述长度太长时上传应用程序时 iTunes Store 操作失败

ios - 当 NSPredicate 匹配带有括号的字符串时崩溃

iphone - 使用 Interface Builder 将 TTImageView 添加到 XIB

ios - 在 MKMapView 中将 KML 文件映射到折线

objective-c - [table reloaddata] 应该只从主线程调用吗?

objective-c - 如何停止当前的 NSOperation?

c# - Xamarin UITableView 行在行选择上展开 - 可能的 iOS?

ios - UIAlertController 上的文本字段触发禁用按钮

ios - UIButton 奇怪的阴影行为

iphone - 如何在 UITableView 单元格文本中进行自动收缩而不隐藏详细信息标签?