Custom view with nib as subview doesn't seem to be loading

Posted by Ben Collins on Stack Overflow See other posts from Stack Overflow or by Ben Collins
Published on 2010-05-04T21:49:37Z Indexed on 2010/05/04 22:08 UTC
Read the original article Hit count: 419

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 int the process of loading my other views from nibs, all the initialization happens for me, but not with this one. Why?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone