1、获取当前控制器
-(UIViewController *)getCurrentVC{
UIViewController *result = nil;
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView *frontView = [[window subviews] objectAtIndex:0];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
result = nextResponder;
else
result = window.rootViewController;
return result;
}
2、获取当前UI控制器
-(UIViewController *)getCurrentUIVC
{
UIViewController *superVC = [self getCurrentVC];
if ([superVC isKindOfClass:[UITabBarController class]]) {
UIViewController *tabSelectVC = ((UITabBarController*)superVC).selectedViewController;
if ([tabSelectVC isKindOfClass:[UINavigationController class]]) {
return ((UINavigationController*)tabSelectVC).viewControllers.lastObject;
}
return tabSelectVC;
}else
if ([superVC isKindOfClass:[UINavigationController class]]) {
return ((UINavigationController*)superVC).viewControllers.lastObject;
}
return superVC;
}
427


——获取当前控制器和获取当前UI控制器&spm=1001.2101.3001.11974&articleId=101227704&d=1&t=3&u=2b848aac46a94aae97495dca059172f7)

被折叠的 条评论
为什么被折叠?



