UIViewController 拆分逻辑

2018-12-25  本文已影响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];
}
上一篇下一篇

猜你喜欢

热点阅读