I've created a custom view that loads its content from a nib, like this:
/* PricingDataView.h */
#import <UIKit/UIKIt.h>
@interface PricingDataView : UIView {
UIView *contentView;
}
@property (nonatomic, retain) IBOutlet UIView *contentView;
@end
/* PricingDataView.m */
#import "PricingDataView.h"
@implementation PricingDataView
@synthesize contentView;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[[NSBundle mainBundle] loadNibNamed:@"PricingDataView" owner:self options:nil];
[contentView setFrame:frame];
[self addSubview:contentView];
}
return self;
}
/* ... */
In the nib file I set PricingDataView
as the type of the File's Owner, and connected the contentView
outlet in IB. I placed a regular UIView
from the Interface Library onto the full-sized view shown to the user, and then changed it's class name to PricingDataView
. It all builds, but at runtime, nothing is rendered where my custom view is supposed to be.
I put breakpoints in PricingDataView.initWithFrame
, but they don't hit, so I know I'm missing something that would cause the view to be initialized. What I'm curious about is that in the process of loading my other views from nibs, all the initialization happens for me, but not with this one. Why?