【发布时间】:2016-05-02 21:36:46
【问题描述】:
我正在尝试创建图像的集合视图。
我已经尝试了这些解决方案来下载图像:
one
two
three
还有
four
var tempObject = json["photos"]
for var i = 0; i < tempObject.count; i++
{
var tempImage = UIImage()
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
tempImage = UIImage(data: NSData(contentsOfURL: NSURL(string:"https://developer.apple.com/swift/images/swift-og.png")!)!)!
})
swiftImages.insert(tempImage, atIndex: i)
}
dispatch_async(dispatch_get_main_queue()) {
self.collectionView?.reloadData()
}
但我无法让它显示图像。我是 swift 网络新手。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! ImageCollectionViewCell
cell.imageView.image = swiftImages[indexPath.row]
return cell
}
【问题讨论】:
标签: ios swift image url networking