.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];
}
网友评论