//获取手机当前显示的ViewController
- (UIViewController*)currentViewController{
UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController;
while (1) {
if ([vc isKindOfClass:[UITabBarController class]]) {
vc = ((UITabBarController*)vc).selectedViewController;
}
if ([vc isKindOfClass:[UINavigationController class]]) {
vc = ((UINavigationController*)vc).visibleViewController;
}
if (vc.presentedViewController) {
vc = vc.presentedViewController;
}else{
break;
}
}
return vc;
}
Get the ViewController currently displayed by the phone
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325848038&siteId=291194637
Recommended
Ranking