The xib
will be instantiated with
- (id)initWithCoder:(NSCoder *)decoder
If you are relying on connections and other objects in the xib
to be available then you may also add code to
- (void)awakeFromNib
which is when the object ... is guaranteed to have all its outlet and action connections already established.
To deal with code duplication you can do something like the following
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}
- (void)commonInit
{
// any common setup
}