【发布时间】:2017-08-02 05:19:18
【问题描述】:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("gallery count : \(self.arrayGallerySingle.count)")
return self.arrayGallerySingle.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gallerycell", for: indexPath) as! GalleryViewCell
return cell
}
//API Fetching method
func galleryFetch(){
let prs = [
"id": dealIDGallery,
"deal_single_page": "1" as String
]
Service.StartWithoutLoading(prs as [String : AnyObject]?, onCompletion: { result in
let jsonResponseSingle = result as? NSDictionary
print(" jsonResponse\(String(describing: jsonResponseSingle))")
if let resultGallery = jsonResponseSingle?.value(forKey: "result") as? NSArray{
for keyValuesGallery in resultGallery {
let gallerySingle = (keyValuesGallery as AnyObject).value(forKey: "gallery_images") as? NSArray
print("Gallery Images Key: \(gallerySingle)")
self.arrayGallerySingle = gallerySingle as! [AnyObject]
DispatchQueue.main.async { () -> Void in
self.collectionView?.reloadData()
}
}
}
})
}
如何在 UICollectionViewCell 上显示带有键 gallery_images 的图像数组?这条线 print("Gallery Images Key: \(gallerySingle)") 在控制台上打印所需的图像数组,但我无法在 collectionView 上显示。我的JSON 回复是http://www.jsoneditoronline.org/?id=8eccb63976d76be7d0b2d1b0e8f02306。我也在我的项目中使用SDWebImage。我已经检查了datasource 连接和collectionView IBoutlet 以及单元格内的图像。我是 Swift 的初学者,请帮助,如果需要任何进一步的信息,请询问
【问题讨论】:
标签: swift3 uicollectionview uicollectionviewcell uicollectionviewlayout