我从API请求3图片url。并且我想要从已获取到Collection View的单元格的url图像中显示3个图像。我是新来的迅速编程从url显示3张图片到Collection View的单元格Swift
这里是我的mainCollectionViewCell代码
class MainCollectionViewController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request(.POST, "URL").responseJSON { response in
if let value = response.result.value {
let json = JSON(value)
let data = json["data"].arrayValue
for datas in data {
let result = datas["image"].stringValue
print(result)
}
}
}
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! MainCollectionViewCell
return cell
}
}
我的图片浏览一个名为mainImageView
这导致将打印图像的URL吗? –
是的,它会打印图片的网址 –
你应该谷歌任何通用教程的Web请求。他们大多数做类似的东西,你想 – Shubhank