2016.4.14
1.自定義cell時吞歼,
若使用nib人芽,使用 registerNib: 注冊,dequeue時會調(diào)用 cell 的 -(void)awakeFromNib
不使用nib,使用 registerClass: 注冊, dequeue時會調(diào)用 cell 的 - (id)initWithStyle:withReuseableCellIdentifier:
文/XiaXiang(簡書作者)
原文鏈接:http://www.reibang.com/p/66420a87b844
著作權(quán)歸作者所有,轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)踪央,并標注“簡書作者”。
使用dequeueReuseableCellWithIdentifier:可不注冊瓢阴,但是必須對獲取回來的cell進行判斷是否為空畅蹂,若空則手動創(chuàng)建新的cell;
if(cell ==nil) {
cell = [[PreSallDetailCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cellid"];
}
使用dequeueReuseableCellWithIdentifier:forIndexPath:必須注冊荣恐,但返回的cell可省略空值判斷的步驟液斜。
xib:
[_tableView registerNib:[UINib nibWithNibName:@"xxxxxCell" bundle:nil] forCellReuseIdentifier:kCellIdentify];
xxxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentify forIndexPath:indexPath];
代碼
[_tableView registerClass:[xxxxxCell class] forCellReuseIdentifier:kCellIdentify];
xxxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentify forIndexPath:indexPath];