开发者

Best way of loading custom cells from a XIB

I have an app, and I'd need custom UITableViewCells, I've been trying different ways, but no one works for what I want, o开发者_如何转开发r simply don't work. Can someone guide me how can I do it? Actually the cell, needs to have some UIImageViews and an UILabel and a UITextView. Thanks in advance!


Create a NIB file with a single UITableViewCell in it.

Loading the cell from the nib is a two liner:

NSArray* objects = [[NSBundle mainBundle] loadNibNamed:@"TheFile" 
                                                 owner:nil
                                               options:nil];
UITableViewCell* cell = [objects objectAtIndex:0];

This method will allways access disk when used, so it can be slow. On iOS 4 and later the is a better help class that caches the NIB in memory, for faster creation. Use like this:

// Cache this one!
UINib* nib = [UINib nibWithNibName:@"TheFile" bundle:nil];

// Then do:
NSArray* objects = [nib instantiateWithOwner:nil
                                     options:nil];
UITableViewCell* cell = [objects objectAtIndex:0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜