Is there a pre-iOS 4 replacement or workaround for UINib?
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!!
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.
精彩评论