3.将父类设计成虚类(设计的核心)
4.新建一个父类
@interface SourceView : UIView
- (void)show;
- (void)hide;
@end
#import "SourceView.h"
@implementation SourceView
- (void)show {
}
- (void)hide {
4.1 再建 子类
@interface ChildOneView : SourceView
@end
@H_404_88@ #import "ChildOneView.h"
@implementation ChildOneView
- (void)show {
@H_404_88@ NSLog(@"ChildOneView");}
- (void)hide {
// todo
}
@end
#import "SourceView.h"
@H_404_88@ #import "ChildTwoView.h"
@interface ChildTwoView : SourceView
@end
@implementation ChildTwoView
- (void)show {
@H_404_88@ NSLog(@"ChildTwoView");}
- (void)hide {
// todo
}
@end
4.2 调用
#import "ViewController.h"
#import "SourceView.h"
#import "ChildOneView.h"
#import "ChildTwoView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SourceView *tmpView = [[ChildTwoView alloc] init];//或[[ChildTwoViewalloc]init]
[tmpView show];
}