我正在我的 iPhone 上测试 RSS。它使用 0 个 nib 文件。我会尽我所能描述它,如果需要,我会发布代码,但我敢打赌,这是一个常见的现象,有一个共同的解决方案。问题出在 tableviewcontroller 中,解决方案可能需要在 CellForRowAtIndexPath 方法中实现。如果我向下滚动,预览图像会停留在各自的位置,直到异步队列为该单元加载正确的图像。因此,如果我有数组项 1 的图像,并且向下滚动到数组项 20,数组项 1 的图像将仍然存在,直到我的队列赶上并加载该图像。如何从我没有查看的单元格中释放图像?感谢您的时间。
这是我的 CellForRow...
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
ArticleItem *object = _objects[indexPath.row];
cell.primaryLabel.text = object.title;
cell.secondaryLabel.text = object.strippedDescription;
cell.primaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.primaryLabel.numberOfLines = 0;
cell.primaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.secondaryLabel.numberOfLines = 0;
//Async dispatch queue for image preview loading...
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *preview = nil;
if (object.iG = nil)
{
preview = [UIImage imageNamed:@"CellLogo.png"];
}
else
{
preview = [UIImage imageWithData:object.iG];
}
dispatch_sync(dispatch_get_main_queue(), ^{
[[cell myImageView] setImage:preview];
[cell setNeedsLayout];
});
});
return cell;
}
如果你收集的话,我有一个 ArticleItem 类,它提取图像 URL 并将它们转换为 data ,我有一个 CustomCell 类,它可以完成它的调用。CustomCell.h @interface CustomCell : UITableViewCell { UIImageView *myImageView; @property(nonatomic,strong)UIImageView *myImageView; @end ================================================= ===== CustomCell.m
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:myImageView];
}
return self;
}
-(void)viewDidUnload {
myImageView = nil;
primaryLabel = nil;
secondaryLabel = nil;
}