iOS UITableView深入

iOS 5.0以后苹果为了简化代码    在TableView向数据源请求数据之前使用-registerNib:forCellReuseIdentifier:方法为@“MY_CELL_ID”注册过nib的话,就可以省下每次判断并初始化cell的代码,要是在重用队列里没有可用的cell的话,runtime将自动帮我们生成并初始化一个可用的cell。

    [tableView registerClass:[YYTableViewCell class] forCellReuseIdentifier:@"uiy"];

    [tableView registerNib:[UINib nibWithNibName:@"YYTableViewCell" bundle:nil] forCellReuseIdentifier:@"uiy"];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    YYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"uiy"];

    return cell;

}

从而省下了这句话

if (!cell) { //如果没有可重用的cell,那么生成一个 

    cell = [[UITableViewCell alloc] init];

}
原文地址:https://www.cnblogs.com/gaojingxuan/p/4929399.html