カスタムUItableViewCell(registerNib:registerClass:との違い)
2247 ワード
UItableViewセルをカスタマイズするには、次の2つの方法があります.
nib
1、xib cell Class cell ( File's Owner class)
2、 tableView registerNib:forCellReuseIdentifier: cell
[_tableView registerNib:[UINib nibWithNibName:@"xxxxxCell" bundle:nil] forCellReuseIdentifier:kCellIdentify];
3、 cellForRowAtIndexPath dequeueReuseableCellWithIdentifier:forIndexPath: cell, cell, nib cell ( dequeueReuseableCellWithIdentifier: )
4、 cell cell, cell awakeFromNib ,
nib
1、 cell initWithStyle:withReuseableCellIdentifier:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
// cell
[self setupView];
}
return self;
}
2、 tableView cell, registerClass:forCellReuseIdentifier: ( Class)
[_tableView registerClass:[xxxxxCell class] forCellReuseIdentifier:kCellIdentify];
3、 cellForRowAtIndexPath dequeueReuseableCellWithIdentifier:forIndexPath: cell, cell, class cell
xxxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentify forIndexPath:indexPath];
4、 cell cell, cell initWithStyle:withReuseableCellIdentifier: cell
:
1、dequeueReuseableCellWithIdentifier: dequeueReuseableCellWithIdentifier:forIndexPath: :
tableView cell Identifier, cell nil;
table cell, cell , cell runtime cell
2、 cell , self.contentView , cell
:
1. cell ,
nib, registerNib: ,dequeue cell -(void)awakeFromNib( xib )
nib, registerClass: , dequeue cell - (id)initWithStyle:withReuseableCellIdentifier:
2. ?
dequeueReuseableCellWithIdentifier: , cell , cell;
dequeueReuseableCellWithIdentifier:forIndexPath: , cell 。