1. 使用dequeueReusableCellWithIdentifier:可不注册,但是必须对返回的cell进行判断,若空则手动创建新的cell;
2. 使用dequeueReusableCellWithReuseIdentifier: forIndexPath:必须注册,返回的cell可省略空值判断,当无可复用cell时runtime将使用注册时提供的资源去新建一个cell并返回;
a. 使用nib,使用 registerNib: 注册,dequeue时会调用 cell 的 -(void)awakeFromNib;
b. 不使用nib,使用 registerClass: 注册, dequeue时会调用 cell 的 - (id)initWithStyle:withReuseableCellIdentifier:;
code:
1.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellID];
}
2.
UITableViewCell *cell = [tableView dequeueReusableCellWithReuseIdentifier:CellID forIndexPath:indexPath];