/**
查找栈中的当前控制器
@return 控制器
*/
- (UIViewController *)findViewControllerInStack {
UIViewController *currVC = nil;
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController ;
do {
if ([rootVC isKindOfClass:[UINavigationController class]]) {
UINavigationController *nav = (UINavigationController *)rootVC;
UIViewController *v = [nav.viewControllers lastObject];
currVC = v;
rootVC = v.presentedViewController;
continue;
} else if ([rootVC isKindOfClass:[UITabBarController class]]){
UITabBarController *tabVC = (UITabBarController *)rootVC;
currVC = tabVC;
rootVC = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
continue;
}
} while (rootVC != nil);
return currVC;
}
网友评论