由于我的应用程序要求,我显示在UITableView中的联系人图像如下所示。UITableView与联系人图像问题
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath
(NSIndexPath *)indexPath
{
//NSMutableArray *sourceArray = sourceList;
static NSString *identifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
//If not possible create a new cell
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.opaque = NO;
CGRect LabelFrame = CGRectMake(130, 33, 150, 13);
callImage = [[UIImageView alloc] initWithFrame:LabelFrame];//phone image
callImage.tag = 1;
[cell.contentView addSubview:callImage];
[callImage release];
-----
-----
}
UIImageView *callImage = (UIImageView *)[cell viewWithTag:1];
ABRecordRef contact = [self getContact];
if(contact && ABPersonHasImageData(contact))
{
UIImage *contactImage = [UIImage imageWithData:(NSData*)ABPersonCopyImageData(contact)];
callImage.image = contactImage;
}
}
我有两个问题,如果我用上面的代码段。
- 表滚动速度太慢。如果评论“图像添加”代码,那么UITable响应速度非常快。
- 内存管理。我的应用程序开始使用25 - 30 MB的RAM。
有没有更好的方法可以避免上述两个问题?
你能发布你的cellForRowAtIndexPath方法的完整代码吗?你的问题可能是你没有正确地重用你的单元格 – Vladimir 2010-03-14 09:26:23
是的,我正在以适当的方式重用它们。无论如何,我发布在我的上述问题本身。 – prathumca 2010-03-15 14:46:37