1.自定義cell時(shí)迁筛,
若使用nib,使用 registerNib: 注冊(cè),dequeue時(shí)會(huì)調(diào)用 cell 的 -(void)awakeFromNib
registerNib注冊(cè): [_tableView registerNib:[UINib nibWithNibName:@"xxxxxCell" bundle:nil] forCellReuseIdentifier:kCellIdentify];
不使用nib酌媒,使用 registerClass: 注冊(cè), dequeue時(shí)會(huì)調(diào)用 cell 的 - (id)initWithStyle:withReuseableCellIdentifier:
registerClass注冊(cè): [_tableView registerClass:[xxxxxCell class] forCellReuseIdentifier:kCellIdentify];
2.需不需要注冊(cè)?
使用dequeueReusableCellWithIdentifier:可不注冊(cè)迄靠,但是必須對(duì)獲取回來(lái)的cell進(jìn)行判斷是否為空秒咨,若空則手動(dòng)創(chuàng)建新的cell;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
? ? if (!cell) {
? ? ? ? cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
? ? ? ? cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
? ? }
使用dequeueReusableCellWithIdentifier:forIndexPath:必須注冊(cè)掌挚,但返回的cell可省略空值判斷的步驟雨席。
xxxCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId forIndexPath:indexPath];