ios开发中怎么获取当前视图的controller
2个回答
展开全部
//获取当前屏幕显示的viewcontroller
+ (BaseViewController *)getCurrentVC
{
BaseViewController *resultVC;
resultVC = [[CBHelper shareHelper] _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
while (resultVC.presentedViewController) {
resultVC = [[CBHelper shareHelper] _topViewController:resultVC.presentedViewController];
}
return resultVC;
}
- (id )_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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询