В соответствии с требованиями моего приложения, я показываю изображения контактов в 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 МБ оперативной памяти.
Есть ли лучший способ избежать двух вышеуказанных проблем?