In order to re-use a certain subview throughout my application (which is storyboard based), I decided to build the subview as a nib, and load it in. To do this, I have done the following:
I have a UIView subclass we can call Widget. I create a corresponding xib file, set the File owner property to my new subclass, hook up the IBOutlets.
Then, in my storyboard, I have a uiview inside of a view controller, and I set its class to the Widget class I created.
Within the widget class, I override initWithCoder, and in there load the nib as follows:
-(id)initWithCoder:(NSCoder *)aDecoder{
if ((self = [super initWithCoder:aDecoder])){
[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"Widget" owner:self options:nil] objectAtIndex:0]];
}
return self;
}
The app would crash at this point, and setting a break point here revealed that initWithCoder was being called over and over again.
It seems like I have mixed two methods for using a nib in this situation, but I'm unclear as to where I went wrong. I can throw up a stack trace if necessary, but it's basically endless nested calls to the same function.