Tuesday, July 6, 2010

Load UIView From Nib

This was a hassle to track down and I actually ended up opening a book. The Internet is not very helpful sometimes. Books still rule, sometimes.

- (void)viewDidLoad {
    [super viewDidLoad];
NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"Blah" owner:self options:nil];
Blah *blah;
for (id object in bundle) {
if ([object isKindOfClass:[Blah class]])
blah = (Blah *)object;
[self.view addSubview: blah];

This assumes a Xib named 'Blah' with its view set to a UIView subclass named 'Blah' (which also exists).

1 comment:

Anonymous said...

Thanks, this really helped me out. Let me know if you want some promo codes for my apps. I'm in the store under the company name eliolhan.