我能够从JSON响应中接收图像数据,我甚至可以使用以下方法将其转换为图像:
let json33 = JSON(data: response.data!)
let allImageStrings = json33["response"]["docs"].flatMap { $0.1["imageData"].first?.1}
for Bro in allImageStrings{
let url = NSURL(string: Bro.string!)
let data = NSData(contentsOfURL: url!)!
let image = UIImage(data: data)
self.anArray.append(image!)
}
self.items = self.anArray
我已创建typealias ItemInfo = UIImage
和private var items: [ItemInfo] = []
private var anArray: [ItemInfo] = []
。
我将anArray
分配给另一个我可以在for-loop items
之外使用的数组,该数组被声明为private var items: [ItemInfo] = []
。并在功能:
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
guard let cell = cell as? CollectViewCell else { return }
let index = indexPath.row % 4
let info = items[index]
//cell.backgroundImageView?.image = self.items //error here
//cell.customTitle.text = info.title
cell.cellIsOpen(cellsIsOpen[indexPath.row], animated: false)
}
我已将@IBOutlet weak var backgroundImageView: UIImageView!
添加到我的手机中。
如何分配获得的base64图像,我甚至将它们转换为UIImage
到集合视图单元格?感谢。