查找当前viewController _ 循环查找

+ (UIViewController*) findBestViewController:(UIViewController*)vc {

if(vc.presentedViewController) {

// Return presented view controller

return[BasicViewControllerfindBestViewController:vc.presentedViewController];

}elseif([vcisKindOfClass:[UINavigationControllerclass]]) {

// Return top view

UINavigationController*svc = (UINavigationController*)vc;

if(svc.viewControllers.count>0)

return[BasicViewControllerfindBestViewController:svc.topViewController];

else

returnvc;

}elseif([vcisKindOfClass:[UITabBarControllerclass]]) {

// Return visible view

UITabBarController*svc = (UITabBarController*)vc;

if(svc.viewControllers.count>0)

return[BasicViewControllerfindBestViewController:svc.selectedViewController];

else

returnvc;

}else{

// Unknown view controller type, return last child view controller

returnvc;

}

}

+ (UIViewController*)currentViewController {

// Find best view controller

UIViewController*viewController = [UIApplicationsharedApplication].keyWindow.rootViewController;

return[BasicViewControllerfindBestViewController:viewController];

}

你可能感兴趣的:(查找当前viewController _ 循环查找)