开发者社区> 问答> 正文

检测视图控制器是否退出

我有一段代码用来检测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语句哪行。不知道怎么解决这个问题?我只需要检测是否这个视图控制器在执行代码,

补充:

异常是:
`
out of bounds
`

展开
收起
爵霸 2016-03-26 09:12:24 1692 0
1 条回答
写回答
取消 提交回答
  • - (void) leftViewDidHide{
    
    if ([((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers count] == 1) {
    SGServerListViewController *sample = [[[((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers objectAtIndex:1]childViewControllers] objectAtIndex:0];
    [sample.serverTableView setUserInteractionEnabled:YES];
    }
    
    
    }
    2019-07-17 19:15:12
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载