2015-09-18 45 views
1

我使用Kingfisher框架從網上下載圖像並緩存它們。我有一個有很多Facebook ID的數組,並且代碼需要下載他們每個人的圖片。現在,代碼會爲newArray [0]下載圖片,但它應該爲存儲在數組中的每個ID執行此操作。重複圖像下載過程

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 
} 

}

任何想法,我怎麼會讓它循環槽的代碼,每一個ID,並在集合視圖中顯示? 任何幫助表示讚賞,真的!謝謝!

回答

0

您可以在您的方法中使用indexPath.row

實施例:

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