开发者

Initializing and loading a custom uitableviewcell

I have Custom uitableviewcell: ScrollViewCell

I want to know what the difference is between the following code

static NSString *CellIdentifier = @"ScrollViewCell";
ScrollViewCell *cell = (ScrollViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    //***** WHAT IS THE DIFFERENCE BETWEEN THIS CODE AND..
    NSArray *xibObj = [[NSBundle mainBundle] loadNibNamed:@"ScrollViewCell" owner:nil options:nil];
    for(id currentObj in xibObj){
        if ([currentObj isKindOfClass:[ScrollViewCell class]]) {
            cell = (ScrollViewCell *) currentObj;
        }
    }
    //***** ..THIS CODE
    cell = [[ScrollViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}开发者_运维问答

Which one should I use and why?


The first example will load a cell from a .xib file in your application's bundle. Each cell can handle it's own code, and behaves a lot like a UIViewController. This approach can get complicated when you try and load data from an array. You have to pass the object you're getting data out of to the cell, and have a very clear design before you start coding.

The other method allocates an empty instance of the UITableViewCell class as normal. This approach is typically used for programmatic configuration of the cells. You'll probably see this one in most places.

Good luck,

Aurum Aquila

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜