我有一段代碼用來檢測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
- (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];
}
}