刚好上周我做了这个,UIViewController *vc = [self topVC:[UIApplication sharedApplication].keyWindow.rootViewController]; //拿到当前页面的VC
[vc.navigationController pushViewController:VC animated:YES];//跳转想去的VC
- (UIViewController *)topVC:(UIViewController *)rootViewController{
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tab = (UITabBarController *)rootViewController;
return [self topVC:tab.selectedViewController];
}else if ([rootViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *navc = (UINavigationController *)rootViewController;
return [self topVC:navc.visibleViewController];
}else if (rootViewController.presentedViewController){
UIViewController *pre = (UIViewController *)rootViewController.presentedViewController;
return [self topVC:pre];
}else{
return rootViewController;
}
}