iOS開發中,建立View常見的兩種方式一個是純代碼,一個是藉助於XIB;建立ViewController常見的也有兩種方式一個是純代碼,一個是藉助於StoryBoard。 經過交流我發現不少童鞋對這些概念都很模糊,因而經過實驗寫一篇博客供參考。bash
@implementation YFView
-(instancetype)init{
self = [super init];
NSLog(@"%s", __func__);
return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:(CGRect)frame];
NSLog(@"%s", __func__);
return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
NSLog(@"%s", __func__);
return self;
}
-(void)awakeFromNib{
[super awakeFromNib];
NSLog(@"%s", __func__);
}
-(void)layoutSubviews{
NSLog(@"%s", __func__);
}
@end
複製代碼
@implementation YFViewController
-(void)loadView{
NSLog(@"%s", __func__);
[super loadView];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"%s", __func__);
self.view.backgroundColor = [UIColor redColor];
}
-(void)viewDidAppear:(BOOL)animated{
NSLog(@"%s", __func__);
[super viewDidAppear:animated];
}
-(instancetype)init{
self = [super init];
NSLog(@"%s", __func__);
return self;
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil];
NSLog(@"%s", __func__);
return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
NSLog(@"%s", __func__);
return self;
}
-(void)awakeFromNib{
NSLog(@"%s", __func__);
[super awakeFromNib];
}
@end
複製代碼
-[YFViewController initWithNibName:bundle:]
-[YFViewController init]
-[YFViewController loadView]
-[YFViewController viewDidLoad]
-[YFViewController viewDidAppear:]
複製代碼
-[YFViewController initWithNibName:bundle:]
-[YFViewController init]
-[YFViewController loadView]
-[YFViewController viewDidLoad]
-[YFViewController viewDidAppear:]
複製代碼
-[ViewController initWithCoder:]
-[ViewController awakeFromNib]
-[ViewController loadView]
-[ViewController viewDidLoad]
-[ViewController viewDidAppear:]
複製代碼
-[YFView initWithFrame:]
-[YFView init]
-[YFView layoutSubviews]
複製代碼
-[YFView initWithFrame:]
-[YFView layoutSubviews]
複製代碼
-[YFView initWithCoder:]
-[YFView awakeFromNib]
-[YFView layoutSubviews]
複製代碼