问题
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!!
回答1:
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.
来源:https://stackoverflow.com/questions/3726406/is-there-a-pre-ios-4-replacement-or-workaround-for-uinib