【发布时间】:2020-05-25 16:45:03
【问题描述】:
我正在使用集合视图在列表中显示 gif。 现在在集合视图中向上或向下滚动单元格时面临单元格可重用问题。
就像 itemA 在列表中的 第一 位和 itemB 在列表中的 第二 位. 但是当我在集合视图中滚动数据时。物品的位置放错了地方。就像某个时间 itemA 排在第 5 位或有时在列表中的任何位置。 我知道我认为这是可重复使用的电池的用途,但不知道如何解决这个问题。 请帮忙。
集合视图 cellForItemAt
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "GifCell", for: indexPath as IndexPath) as? GifCell else {
fatalError()
}
if gifArr.count > 0 {
let urlString = self.gifArr[indexPath.row]
let url = URL(string: urlString)!
DispatchQueue.global().async {
let imageData = try? Data(contentsOf: url)
let imageData3 = FLAnimatedImage(animatedGIFData: imageData) // this is the 3rd pary library to show the gifs on UIimageview's
DispatchQueue.main.async {
cell.imageView.animatedImage = imageData3
cell.textLabel.text = String(indexPath.row)
}
}
}
return cell
}
【问题讨论】:
-
这能回答你的问题吗? UICollection Cells are mixed in swift
标签: ios iphone swift3 uicollectionview swift4