我正在使用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 :(得分:0)
您可以在方法中使用indexPath.row
。
示例:
let URL = NSURL(string: "http://graph.facebook.com/" + newArray[indexPath.row] + "/picture?type=large")!