iphone - 检查导航堆栈上的 ViewController 是否存在

标签 iphone ios objective-c cocoa-touch uinavigationcontroller

我这里有这段代码来检查 ViewController 是否存在。不幸的是它不起作用。问题是,它是在 此刻Navigation Stack 中弹出的另一个 VC 执行的:

- (void) leftViewDidHide{
    if ([((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers objectAtIndex:1]) {
    SGServerListViewController *sample = [[[((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers objectAtIndex:1]childViewControllers] objectAtIndex:0];
    [sample.serverTableView setUserInteractionEnabled:YES];
    }
}

应用程序崩溃,异常断点将我指向带有 if 语句的行。关于这里可能出什么问题的任何想法?我只是想检查这个 VC 是否存在,如果存在 - 执行代码。

最佳答案

NSArray *viewControlles = [self.navigationController.viewControllers];

for (int i = 0 ; i <viewControlles.count; i++){ 
  if ([YourVC isKindOfClass:[viewControlles objectAtIndex:i]]) {
          //Execute your code
      }
}

关于iphone - 检查导航堆栈上的 ViewController 是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378817/

相关文章:

android - 以相同的格式从 iOS 和 Android 获取设备语言

ios - 添加 View Controller 作为启动屏幕

ios - 如何将UITableView单元格移到UITableView之外的另一个 View ?

iphone - 如何设置iPhone视频输出图像大小

iphone - 在 UIWebView 视频播放期间允许 UIInterfaceOrientationLandscape

iphone - initWith BarButtonSystemItem :UIBarButtonSystemItemPageCurl not working

ios - Test-Flight App Beta 测试时间限制

iphone - 如何检测 iOS 设备是否支持模糊效果?

ios - 如何播放嵌入在 UIView 中的视频?

iphone - 类的全局实例