for_2012 2013-01-18 05:21 采纳率: 0%
浏览 2202
已采纳

检测视图控制器是否退出

我有一段代码用来检测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

  • 写回答

3条回答 默认 最新

  • Kill_it 2013-01-18 05:59
    关注
    - (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];
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料