不使用storyboard的时候会调用:
init
initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
代码:
-(instancetype)init{
if (self = [super init]) {
}
return self;
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
return self;
}
小知识:
同时调用时,先走 initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 然后再走 init 方法
使用storyboard的时候会调用:
initWithCoder:(NSCoder *)aDecoder
awakeFromNib
代码:
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
if (self = [super initWithCoder:aDecoder]) {
}
return self;
}
-(void)awakeFromNib{
[super awakeFromNib];
}
小知识:
同时调用时,先走 initWithCoder:(NSCoder *)aDecoder 然后再走 awakeFromNib 方法