views:

76

answers:

2

My application features a tableview which contains some rather complex tableviewcells. Therefore, these cells have been designed in Interface Builder and are instanciated later as needed using UINib which allows just that - load the content from a nib and instanciate it as needed.

But UINib is only available for iOS 4.0 and above.
Before I go ahead and abandon all the 3.x users, is there a way to (easily) recreate what I'm doing using pre-iOS4 classes and methods?

Thanks alot!!

A: 

You can load views from a nib using the following:

NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyNibFilename" owner:self options:nil];
UITableViewCell* cell = (UITableViewCell*)[nibContents objectAtIndex:0];

Note that the index you supply to objectAtIndex: is determined by the order of the views in the nib. If the only thing in the nib is your custom table view cell, then 0 is likely the correct index.

EDIT:

It is a documented UIKit addition to NSBundle.

imaginaryboy
You're right! Thanks! Do you happen to know where this method is being defined? The NSBundle class reference doesn't mention loadNibNamed at all.. thanks again!
Toastor