I noticed that if you load connected views from nib, you need to override initWithCoder, if you want to add the initialization code, because the designated initializer is not called (which makes sense), and if you do not load the view from the tip, then the same code should be executed in the designated initializer.
So, in order to handle both cases, you need the same initialization code in both methods.
This is the best solution I've come up with so far, but I need to think about whether there is an even more common way to do this. This code is in a subclass of UITableViewCell, but it can be any UIView:
- (void)didFinishInitializingOrUnacrhiving { } - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self didFinishInitializingOrUnacrhiving]; } return self; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self didFinishInitializingOrUnacrhiving]; } return self; }
So, any thoughts on this? Is this the โright wayโ to do something, are there potential traps here, or am I just missing something?
source share