通常我们在Cell nil的条件之外配置Cell。在我的情况下,我正在做同样的事情,将 NSData 转换为 Cell nil 之外的图像。这样,每次我触发请求并重新加载表时,它都会完美地将数据转换为特定单元格的图像。但是在重新加载表格后,我的问题是当我滚动表格时,每次它都会将 NSData 转换为图像,这很明显。我需要在重新加载表格后避免在滚动时进行这种转换。
static NSString *CellIdentifierImage = @"CellIdentifierImage";
if(indexPath.section == 0)
{
NewsImageCell *newsImageCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierImage];
if (newsImageCell == nil)
{
NSLog(@"CellNil");
newsImageCell = [[NewsImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierImage];
newsImageCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if([[ApplicationData sharedInstance].arrTop10NewsHome count]>0)
{
NSMutableDictionary *dicSource = [arrSource objectAtIndex:indexPath.row];
NSURL *urlImage = [NSURL URLWithString:[dicSource retrieveForPath:@"ItemImage"]];
newsImageCell.lblNewsHeading.text = [dicSource objectForKey:@"Title"];
[newsImageCell.loadingIndicator startAnimating];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:urlImage]];
dispatch_sync(dispatch_get_main_queue(), ^{
newsImageCell.imgVwNews.image = image;
[newsImageCell.loadingIndicator stopAnimating];
});
});
}
return newsImageCell;
}
提前感谢您的想法!