[英]IOS - SWIFT - CollectionView With images, loading URLs from array
我有一個具有不同圖像URL的集合視圖和數組。 當我啟動應用程序時,集合視圖開始通過數組加載圖像:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CellView
var url = arr[indexPath.row]
var urls = NSURL(string: url)
var data = NSData(contentsOfURL: urls!)
cell.ImageView.image = UIImage(data: data!)
return cell
}
麻煩就出現了:例如,在第4個單元格收集視圖中,加載所有4個單元格的所有4個網址,這花費了很多時間。 集合視圖如何為特定單元格加載特定的URL,而又不花時間將URL加載到已加載的單元格?
謝謝你的幫助!!
我建議為此使用第三方庫,它稱為SDWebImage 。
並且比單元集內的每個圖像視圖:
self.imageView.sd_setImageWithURL(url, completed: block)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.