美文网首页
跳转VC 处理优化

跳转VC 处理优化

作者: 失忆的程序员 | 来源:发表于2020-05-06 11:05 被阅读0次

/**

获取当前的viewController

@return viewController

*/

- (UIViewController *)on_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;

}

// 使用

[[self on_topViewController] presentViewController:<#name#> animated:YES completion:nil];

相关文章

网友评论

      本文标题:跳转VC 处理优化

      本文链接:https://www.haomeiwen.com/subject/xkmightx.html