您的位置:首页 > 产品设计 > UI/UE

UITableVIew的性能优化-重用原理

2015-07-14 22:40 405 查看
UITableVIew的性能优化:使用方法创建cell时,先优先从缓存池中找cell,找不到再创建新的cell,并且要绑定Identifer标示。

代码:

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

// 定义一个静态的标识(只会初始化一次,内存分配一次)

static NSString *ID = @"c1";

// 优先从缓存池中去找cell

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];

// 缓存池中找不到就创建一个新的cell,一定要绑定标示

if (cell == nil) {

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

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: