在Objective-C中,是否有必要覆盖子类的所有继承构造函数以添加自定义初始化逻辑?覆盖子类中的init
例如,将下面是一个UIView
子类定制的初始化逻辑是否正确?
@implementation CustomUIView
- (id)init {
self = [super init];
if (self) {
[self initHelper];
}
return self;
}
- (id)initWithFrame:(CGRect)theFrame {
self = [super initWithFrame:theFrame];
if (self) {
[self initHelper];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (self) {
[self initHelper];
}
return self;
}
- (void) initHelper {
// Custom initialization
}
@end
所以,即使我实例CustomUIView用普通的init,它会调用initWithFrame? – hpique 2010-12-05 16:39:54