获取当前控制器
+ (UIViewController *)getCurrentVC {
UIViewController* vc;
UITabBarController* tbc = (UITabBarController* )[[[UIApplication sharedApplication].delegate window] rootViewController];
if ([tbc isKindOfClass:[UITabBarController class]]) {
if (!tbc.presentedViewController) {
UINavigationController* nav = tbc.selectedViewController;
vc = [nav.viewControllers lastObject];
} else {
if ([tbc.presentedViewController isKindOfClass:[UINavigationController class]]) {
vc = [((UINavigationController* )tbc.presentedViewController).viewControllers lastObject];
} else {
vc = tbc.presentedViewController;
}
}
} else {
if ([tbc isKindOfClass:[UINavigationController class]]) {
vc = [((UINavigationController* )tbc).viewControllers lastObject];
} else {
vc = tbc;
}
}
return vc;
}
网友评论