开发者社区 问答 正文

检测视图控制器是否退出

我有一段代码用来检测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 1819 分享 版权
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
    赞同 展开评论
问答地址: