//获取当前控制器
+ (UIViewController *)getCurrentVC {
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
UIViewController* currentViewController = window.rootViewController;
BOOL runLoopFind = YES;
while (runLoopFind) {
if (currentViewController.presentedViewController) {
currentViewController = currentViewController.presentedViewController;
} else {
if ([currentViewController isKindOfClass:[UINavigationController class]]) {
currentViewController = ((UINavigationController *)currentViewController).visibleViewController;
} else if ([currentViewController isKindOfClass:[UITabBarController class]]) {
currentViewController = ((UITabBarController* )currentViewController).selectedViewController;
} else {
break;
}
}
}
return currentViewController;
}
IOS开发获取当前页面的控制器
最新推荐文章于 2024-09-11 11:00:10 发布