+ (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];
}