0
点赞
收藏
分享

微信扫一扫

UIView 直接push的方法

萍儿的小确幸 2021-09-19 阅读 72

朋友介绍的 很好用

.h

#import

@interface HXGetTheViewController : NSObject

+ (UIViewController *)getNowViewController;

@end

.m

+ (UIViewController *)getNowViewController {

    UIViewController * getVc = [UIApplication sharedApplication].keyWindow.rootViewController;

    while(1) {

        //根据不同的页面切换方式,逐步取得最上层的viewController

        if ([getVc isKindOfClass:[UITabBarController class]]) {

            getVc = ((UITabBarController *)getVc).selectedViewController;

        }

        if ([getVc isKindOfClass:[UINavigationController class]]) {

            getVc = ((UINavigationController *)getVc).visibleViewController;

        }

        if (getVc.presentedViewController) {

            getVc = getVc.presentedViewController;

        }else{

            break;

        }

    }

    returngetVc;

}

调用

FindPasswordViewController *joinVC = [FindPasswordViewController new];

    UIViewController *getVC = [HXGetTheViewController getNowViewController];

    joinVC.type=1;

    [getVC.navigationController pushViewController:joinVC animated:YES];

举报

相关推荐

0 条评论