美文网首页
TableView单元格对优化(重用)

TableView单元格对优化(重用)

作者: xing_zhu | 来源:发表于2016-10-13 17:54 被阅读29次

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

{

//被static修饰的局部变量,只会初始一次。整够运行过程中只有一份内存

staticNSString*ID =@"cell";

//1、先根据Cell的标识符去缓存池中查找可以利用的Cell

UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:ID];

//如果Cell为空创建Cell并给相应的标识符

if (cell == nil) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];

}

//3、数据覆盖

cell.textLabel.text= [NSStringstringWithFormat:@"%zd",indexPath.row];

NSLog(@"%p-----%zd",cell, indexPath.row);

returncell;

}

相关文章

网友评论

      本文标题:TableView单元格对优化(重用)

      本文链接:https://www.haomeiwen.com/subject/dfawyttx.html