Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标C用户界面收集问题_Objective C_Uitableview_Lazy Loading_Objective C Blocks - Fatal编程技术网

Objective c 目标C用户界面收集问题

Objective c 目标C用户界面收集问题,objective-c,uitableview,lazy-loading,objective-c-blocks,Objective C,Uitableview,Lazy Loading,Objective C Blocks,说明:- 您好,当我们运行这段代码时,当单元格重新定位图像在滚动时发生变化 请让我知道如何修理 - (UICollectionViewCell )collectionView:(UICollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cellidentifier"; CollectionViewCell *c

说明:-

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

请让我知道如何修理

- (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;
}

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

您好,我们尝试了此处提到的相同想法,但使用您的想法,它不会显示任何像旧图像或新图像这样的图像。任何其他解决方案。最好将数据加载到您的模型中,而不是加载到视图中,当模型准备就绪时,您可以从您的模型填充视图,这通常是标准方法。