当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Repeat process for image download

问题描述:

I am using Kingfisher framework to download images from the web and cache them. I have an array with a lot of Facebook id's, and the code needs to download the picture of each of them. Right now, the code downloads the picture for newArray[0], but it should do that for every id stored in the array.

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return newArray.count

}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewCell", forIndexPath: indexPath) as! CollectionViewCell

cell.imageView.kf_showIndicatorWhenLoading = true

let URL = NSURL(string: "http://graph.facebook.com/" + newArray[0] + "/picture?type=large")!

cell.imageView.kf_setImageWithResource(Resource(downloadURL: URL), placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in

}) { (image, error, cacheType, imageURL) -> () in

}

return cell

}

}

Any idea how I would make it loop trough the code for every id and display it in the collection view?

Any help is appreciated, really! Thanks!

网友答案:

You can use indexPath.row in your method.

Example:

let URL = NSURL(string: "http://graph.facebook.com/" + newArray[indexPath.row] + "/picture?type=large")!
分享给朋友:
您可能感兴趣的文章:
随机阅读: