标签:重用标识符
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//重用标识符
static NSString * identifider = @"reuse";
//去重用队列中根据标识符取可重用的cell
AddressBookCell * cell = [tableView dequeueReusableCellWithIdentifier:identifider];
if (!cell) {
cell = [[[AddressBookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifider] autorelease];
cell.delegate = self;
}
cell.indexPath = indexPath;
//先获取key
//key 对应的数组
//数组中获取元素对象
cell.nameLabel.text = ((AddressPerson *)(self.addressBook[ self.orderedKeys[indexPath.section]][indexPath.row])).name;
cell.phoneNumber.text = ((AddressPerson *)(self.addressBook[ self.orderedKeys[indexPath.section]][indexPath.row])).phoneNumber;
cell.photoView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:((AddressPerson *)(self.addressBook[ self.orderedKeys[indexPath.section]][indexPath.row])).imageName]];
return cell;
}
//重用机制
//1. 创建重用标识符 ,
static NSString * identifier = @"lanouhn";
//2. 去重用队列取出可重用的cell
StudentCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//3. 判断是否成功取到可重用的cell .
if (!cell) {
//如果没有成功取到可重用的cell ,就创建一个cell
//创建cell之后一定要给cell贴一个重用标识符 , 方便别人重用
cell = [[[StudentCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];
// NSLog(@"%d",_num ++);
}
//cell.textLabel.text = @"ffff";
// cell.detailTextLabel.text = @"dddd";
cell.la.text = @"gagaga";
return cell;
标签:重用标识符
原文地址:http://qccccc.blog.51cto.com/6004423/1548896