IOS - SWIFT - CollectionView With images, loading URLs from array -
i have collection view , array urls of different images. , when launch app, collection view starts load images through array:
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 }
and trouble appearse: example on 4th cell collection view loading 4 urls 4 cells , takest alot time. how can collection view load particular url particular cell , don't spend time load urls cells loaded?
thanks help!!
i suggest using third party library matter, called sdwebimage.
and each image view inside cell set:
self.imageview.sd_setimagewithurl(url, completed: block)
Comments
Post a Comment