【发布时间】:2017-06-17 17:08:58
【问题描述】:
我是 swift3 的初学者,在从 UICollectionView 中获取图像时遇到问题。我按照本教程(https://github.com/zhangao0086/DKImagePickerController)从照片库上传多张图片,但我不知道如何从 UICollectionView 中检索图片。
来自 ViewController 的代码
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let asset = self.assets![indexPath.row]
var cell: UICollectionViewCell?
var imageView: UIImageView?
if asset.isVideo {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellVideo", for: indexPath)
imageView = cell?.contentView.viewWithTag(1) as? UIImageView
} else {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellImage", for: indexPath)
imageView = cell?.contentView.viewWithTag(1) as? UIImageView
}
if let cell = cell, let imageView = imageView {
let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
let tag = indexPath.row + 1
cell.tag = tag
asset.fetchImageWithSize(layout.itemSize.toPixel(), completeBlock: { image, info in
if cell.tag == tag {
imageView.image = image
}
})
}
return cell!
}
非常感谢任何帮助。
非常感谢!
【问题讨论】:
-
你到底想要什么?
标签: ios image swift3 uicollectionview