美文网首页
UIViewController 拆分逻辑

UIViewController 拆分逻辑

作者: 风___________ | 来源:发表于2018-12-25 15:41 被阅读8次

    .h

    
    #import <UIKit/UIKit.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    @interface UIViewController (DidLoadInit)
    - (void)setController;
    - (void)backViewInit;
    - (void)getModel;
    
    @end
    
    NS_ASSUME_NONNULL_END
    
    

    .m

    #import "UIViewController+DidLoadInit.h"
    #import <objc/runtime.h>
    
    @implementation UIViewController (DidLoadInit)
    + (void)load{
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            Method originalMethod = class_getInstanceMethod(self, @selector(viewDidLoad));
            Method swizzledMethod = class_getInstanceMethod(self, @selector(jc_viewDidLoad));
            method_exchangeImplementations(originalMethod, swizzledMethod);
        });
    }
    
    - (void)jc_viewDidLoad {
        [self jc_viewDidLoad];
        [self setController];
        [self backViewInit];
        [self getModel];
    }
    
    - (void)setController{
    }
    - (void)backViewInit{
    }
    - (void)getModel{
    }
    @end
    

    use

    #import "UIViewController+DidLoadInit.h"
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    - (void)setController{
    }
    - (void)backViewInit{
        self.bg = [[ShowEnglishView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:self.bg];
    }
    - (void)getModel{
        [self postData];
    }
    

    相关文章

      网友评论

          本文标题:UIViewController 拆分逻辑

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