【发布时间】:2017-03-06 10:08:23
【问题描述】:
我想从提供图像 url 的 api 中获取图像,我需要另一个 api 调用来从他们的 url 下载图像吗?我如何抓取每个图像并将其附加到数组中并将它们显示在我的集合视图单元格中。我已经在类范围之外声明了这一点
var videoArray = [funnyVideos]()
Alamofire.request(_url).responseJSON { (response) in
print(response.result.value!)
if let dict = response.result.value as? Dictionary<String, AnyObject> {
if let result = dict["result"] as? Dictionary<String, AnyObject> {
if let data = result["data"] as? [Dictionary<String, AnyObject>] {
for obj in data {
let mainObj = funnyVideos()
mainObj.parseData(from: obj)
videoArray.append(mainObj)
// print (obj)
}
if let image1 = data[0]["image"] as? String {
print(image1)
}
self.collection.reloadData()
}
}
}
completed()
}
这个函数是另一个类:搞笑视频
func parseData(from: Dictionary<String, AnyObject>){
if let name = from["title"] as? String{
self._name = name.capitalized
}
}
这个函数配置单元是另一个类,它包含集合单元的标签和图像视图的出口。
func configureCell(_ funny : funnyVideos) {
self.funny = funny
nameLabel.text = self.funny.name.capitalized
// imageView.image = UIImage()
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
fun = videoArray[indexPath.row]
cell.configureCell(fun)
}
我有什么选项可以从 UIImage 容器中的 url 获取它们? print(image1) 打印图像的 url。
【问题讨论】:
-
修复代码格式
标签: ios swift3 uiimage xcode8 uicollectionviewcell