Every Cocoa Touch (and Cocoa) class has a designated initializer; for UIView
, as stated in this documentation, that method is initWithFrame:
. In this particular case, you'll only need to override initWithFrame
; all other calls will cascade down and hit this method, eventually.
This goes beyond the scope of the question, but if you do end up creating a custom initializer with extra parameters, you should make sure to the designated initializer for the superclass when assigning self
, like this:
- (id)initWithFrame:(CGRect)theFrame puzzle:(Puzzle *)thePuzzle title:(NSString *)theTitle {
self = [super initWithFrame:theFrame];
if (self) {
[self setPuzzle:thePuzzle];
[self setTitle:theTitle];
[self initHelper];
}
return self;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…