Warning: Attempt to present <CallViewController: 0x1281cd200> on <MainControllerViewController: 0x127833800> whose view is not in the window hierarchy!
//可以获取当前的controller(最上方的controller)
(UIViewController*)topViewController
{
return [self topViewControllerWithRootViewController:self.window.rootViewController];
}(UIViewController)topViewControllerWithRootViewController:(UIViewController)rootViewController
{
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController tabBarController = (UITabBarController )rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController navigationController = (UINavigationController)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}