Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Ios 滚动后集合视图中的视图更新太晚_Ios_Swift_Scroll_Uicollectionview - Fatal编程技术网

Ios 滚动后集合视图中的视图更新太晚

Ios 滚动后集合视图中的视图更新太晚,ios,swift,scroll,uicollectionview,Ios,Swift,Scroll,Uicollectionview,我有CollectionView,每个单元格内都有图像。 滚动此集合时,新单元格(indexPath=10)包含旧单元格(indexPath=1)中的图像,然后调用此方法: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { } 我将图像URL设置为新视图。 更新前滚动后隐藏旧图像的最佳方法是什么?重新使

我有CollectionView,每个单元格内都有图像。 滚动此集合时,新单元格(indexPath=10)包含旧单元格(indexPath=1)中的图像,然后调用此方法:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

}
我将图像URL设置为新视图。
更新前滚动后隐藏旧图像的最佳方法是什么?

重新使用图像时,您需要清理CollectionViewCell中的图像。 重写CollectionViewCell子类中的
prepareforeuse
函数

  override func prepareForReuse() {
        super.prepareForReuse()
        // Set the cell's imageView's image to nil
        self.imageView.image = nil
    }

重复使用图像时,需要清理CollectionViewCell中的图像。 重写CollectionViewCell子类中的
prepareforeuse
函数

  override func prepareForReuse() {
        super.prepareForReuse()
        // Set the cell's imageView's image to nil
        self.imageView.image = nil
    }


您正在从url下载图像吗?在请求使用ulr的新图像之前,请尝试将图像设置为nil。这样,由于单元格的重复使用,在从serverIts接收到映像之前,它将是空的。你可以发布
func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->UICollectionViewCell
异步图像的代码吗?异步图像的工作方式与tihs类似,你只能使用占位符直到加载为止。你是从url下载图像吗?在使用ulr请求新图像之前,请尝试将图像设置为nil。这样,由于单元格的重复使用,在从serverIts接收到映像之前,它将是空的。你可以发布
func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->UICollectionViewCell
Async图像的代码吗?异步图像的工作方式与tihs类似,你只能使用占位符直到加载。请注意,此方法从iOS 8开始可用,以前,这必须由程序员在对cell@RohanBhale事实并非如此。CollectionView自iOS6起可用,而函数
prepareforeuse
也自iOS6起可用。请参阅从iOS 6开始提供的API文档@dirtydanee UICollectionReusableView的截图,该方法可用于iOS 8onwards@RohanBhale根据文档,这是不正确的。@dirtydanee我说这是专门针对swift的,因为所讨论的代码是在swift中的。请注意,这种方法从iOS 8开始就可用,以前这必须由程序员在删除cell@RohanBhale事实并非如此。CollectionView自iOS6起可用,而函数
prepareforeuse
也自iOS6起可用。请参阅API文档@dirtydanee UICollectionReusableView的截图,该文档从iOS 6开始提供,该方法从iOS 8开始提供onwards@RohanBhale根据文档,这是不正确的。@dirtydanee我是专门为swift说的,因为所讨论的代码在swift中