// 获取顶层控制器
//- (UIViewController *)topViewController {
// UIViewController *resultVC;
// resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
// while (resultVC.presentedViewController) {
// resultVC = [self _topViewController:resultVC.presentedViewController];
// }
// return resultVC;
//}
//- (UIViewController *)_topViewController:(UIViewController *)vc {
// if ([vc isKindOfClass:[UINavigationController class]]) {
// return [self _topViewController:[(UINavigationController *)vc topViewController]];
// } else if ([vc isKindOfClass:[UITabBarController class]]) {
// return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
// } else {
// return vc;
// }
// return nil;
//}
//获取顶层控制器
- (MTDBaseViewController *)viewController
{
for(UIView*next = [selfsuperview]; next; next = next.superview) {
UIResponder*nextResponder = [nextnextResponder];
if([nextResponderisKindOfClass:[UIViewControllerclass]]) {
return(MTDBaseViewController*)nextResponder;
}
}
return nil;
}