0

I'm trying to load json data containing images to table. I want to load images one by one in cells.but my code load images at once and main problem is that I can't click to any buttons in view till images load completely here is my code :

 override func viewWillAppear(_ animated: Bool) {

     DispatchQueue.global(qos: .background).async {
        self.JsonGoodsData(rdc: relCode, pageIndex: 1)
        DispatchQueue.main.async {

        }
    }

and in 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()
     })
 }
maral
  • 259
  • 4
  • 18

0 Answers0