我试图将包含图像的json数据加载到表中。我想在单元格中逐个加载图片。但我的代码一次加载图像,主要问题是我无法点击视图中的任何按钮,直到图像完全加载到这里是我的代码:
override func viewWillAppear(_ animated: Bool) {
DispatchQueue.global(qos: .background).async {
self.JsonGoodsData(rdc: relCode, pageIndex: 1)
DispatchQueue.main.async {
}
}
并在jsonGoodsData中:
for item in 0..<catsCount {
var catItem: NSDictionary
var itemStruct = good(GoodsFinalCode: 0, GoodsFullName: "", GPackDayPrice: 0, ImgUrl: defaultImg, Latitude: 0, Longitude: 0, Address: "", Mins: 0)
catItem = fetchedData[item] as! NSDictionary
itemStruct.Address = catItem["Address"]! as! String
itemStruct.GoodsFinalCode = catItem["GoodsFinalCode"]! as! Int
itemStruct.GoodsFullName = catItem["GoodsFullName"]! as! String
itemStruct.GPackDayPrice = catItem["GPackDayPrice"]! as! Int
////////////////////
if let img = catItem["ImgUrl"]as? String {
itemStruct.ImgUrl = urlToImage(urlStr: img)
}
///////////////////
itemStruct.Latitude=catItem["Latitude"]! as! Double
itemStruct.Longitude=catItem["Longitude"]! as! Double
itemStruct.Mins=catItem["Mins"]! as! Int
self.goods.append(itemStruct)
DispatchQueue.main.async(execute: {self.itemsTable.reloadData()
})
}