【问题标题】:Objective C UI Collection issue目标 C UI 集合问题
【发布时间】:2015-12-20 08:52:07
【问题描述】:

说明:-

您好,当我们运行此代码时,单元格重定位图像在滚动时发生变化。

请告诉我如何解决。

- (UICollectionViewCell )collectionView:(UICollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cellidentifier";
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    NSString * string = [_temp objectAtIndex:indexPath.row];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // retrive image on global queue
        UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL:     [NSURL URLWithString:string]]];

        dispatch_async(dispatch_get_main_queue(), ^{
            cell.imageView.image = img;
        });
    });

    return cell;
}

【问题讨论】:

  • 最好将数据加载到您的 model 而不是 view 中,并且当 model 是准备好你可以从你的 model 填充 view - 通常这是标准方式。

标签: objective-c uitableview lazy-loading objective-c-blocks


【解决方案1】:

这里的问题是,如果单元格被重复使用,之前的图像可能仍在加载或设置中。您可以将单元格的prepareForReuse 覆盖为nil 图像。对于图像的异步加载,您应该检查单元格的模型对象是否仍然与开始加载时相同,如果不是,则不要将图像设置为太迟。

【讨论】:

  • 您好,我们尝试了这里提到的相同想法,但使用您的想法,它没有显示任何图像,如旧图像或新图像。还有其他解决方案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-04
  • 2015-12-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多