When am I supposed to use the initWithCoder: method?
2 Answers
Yes, if you are using a custom class in IB, then those objects are instantiated with the initWithCode: method. So, in your class you would override:
-(id) initWithCoder:(NSCoder*)aDecoder {
if (! (self = [super initWithCoder:aDecoder]))
return nil;
// object has been created from IB... do initialization stuff here
return self;
}
Comments
You are supposed to use the initWithCoder: method when you are working with objects that have been archived. For example when you specifically use NSKeyedUnarchiver to create these archived objects or when you need to add custom initialization code to objects that are coming from a xib file.
1 Comment
Christian Gossain
the reason I ask is because i've created a subclass of UIScrollView, i'd like to set it position in the xib and grab that info and use it to set up the subclass, would I use initWithCoder: for something like that?