objective-c版本
一、需要跳转到的页面的上一级页面(EHRDiagnoseListViewController),将其加入数组中,避免返回时返回到当前页面中,造成死循环
//取到当前导航控制器的所有子元素(即子控制器,childControllers)
NSMutableArray *navCtrArray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[navCtrArray removeLastObject]; //移除子元素中倒数第一个控制器
[navCtrArray removeLastObject]; //移除子元素中倒数第二个控制器
//ScanMedicalDetailViewController的上级界面。
EHRDiagnoseListViewController *listCtr = [[EHRDiagnoseListViewControlleralloc]init];
二、真正需要跳转到的页面(ScanMedicalDetailViewController)
ScanMedicalDetailViewController *scanCtr = [[ScanMedicalDetailViewControlleralloc]init];
[navCtrArray addObject:listCtr]; //将listCtr添加到当前导航控制器的倒数第二个位置
[navCtrArray addObject:scanCtr];//将scanCtr添加到当前导航控制器的最后位置,即栈顶
listCtr.hidesBottomBarWhenPushed=YES;
scanCtr.hidesBottomBarWhenPushed=YES;
[self.navigationController setViewControllers:navCtrArray];
[navCtrArray removeLastObject];
swift版本
let detailVC = EmrPhotoDetailViewCtr()
var navArray:[UIViewController] = []
for i in0...(self.navigationController?.childViewControllers.count)!-1{
let vc=self.navigationController?.childViewControllers[i]
navArray.append(vc!)
}
navArray.removeLast()
navArray.append(detailVC)
self.navigationController?.setViewControllers(navArray, animated:true)