美文网首页
子线程push一个controller 引起的崩溃

子线程push一个controller 引起的崩溃

作者: 韩喵 | 来源:发表于2019-03-27 14:36 被阅读0次

感谢大佬给的解答

创建 UINavigationController+Main.h 文件

.h文件 

#import

NS_ASSUME_NONNULL_BEGIN

@interfaceUINavigationController (Main)

@end

NS_ASSUME_NONNULL_END

.m文件

#import "UINavigationController+Main.h"

#import

@implementationUINavigationController (Main)

+ (void)load {

    staticdispatch_once_tonceToken;

    dispatch_once(&onceToken, ^{

        MethodoriM =class_getInstanceMethod([selfclass],@selector(pushViewController:animated:));

        MethodrepM =class_getInstanceMethod([selfclass],@selector(p_pushViewController:animated:));

        method_exchangeImplementations(oriM, repM);

    });

}

- (void)p_pushViewController:(UIViewController*)viewController animated:(BOOL)animated {

    dispatch_async(dispatch_get_main_queue(), ^{

        [selfp_pushViewController:viewControlleranimated:animated];

    });

}

@end

其他的什么也不用动 

相关文章

网友评论

      本文标题:子线程push一个controller 引起的崩溃

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