由於我的應用程序要求,我顯示在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