如何使用swift3在TableViewCell的CollectionViewCell中从服务器dynamic显示数据?

我从TableViewCell获取了json链接数据,然后从服务器检索这些数据,并在与相关TableViewCell数据的collectionView中显示。 如何在swift3中显示这些数据? 请帮帮我。

我从TableViewCell中获得了url链接(mainThemeList.main_associated_url,main_name)。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let mainThemeList = mainHomeThemeTable[(indexPath as NSIndexPath).row] let cell = tableView.dequeueReusableCell(withIdentifier: "homecell") as! HomeCategoryRowCell DispatchQueue.main.async { cell.categoryTitle.text = mainThemeList.main_name cell.mainAssociatedURL.text = mainThemeList.main_associated_url self.prefs.set(mainThemeList.main_name, forKey: "main_name") cell.categoryTitle.font = UIFont.boldSystemFont(ofSize: 17.0) cell.collectionView.reloadData() } DispatchQueue.main.async { self.retrieveDataFromServer(associated_url: mainThemeList.main_associated_url,main_name: mainThemeList.main_name) } return cell } 

然后从服务器的数据相关的URL链接数据。

  private func retrieveDataFromServe(associated_url : String , main_name: String) { SwiftLoading().showLoading() if Reachability().isInternetAvailable() == true { self.rest.auth(auth: prefs.value(forKey: "access_token") as! String!) rest.get(url: StringResource().mainURL + associated_url , parma: [ "show_min": "true" ], finished: {(result : NSDictionary, status : Int) -> Void in self.assetsTable.removeAll() if(status == 200){ let data = result["data"] as! NSArray if (data.count>0){ for item in 0...(data.count) - 1 { let themes : AnyObject = data[item] as AnyObject let created = themes["created"] as! String let assets_id = themes["id"] as! Int let name = themes["name"] as! String var poster_img_url = themes["poster_image_url"] as! String let provider_id = themes["provider_id"] as! Int poster_img_url = StringResource().posterURL + poster_img_url self.assetsTable.append(AssetsTableItem(main_name: main_name,created: created,assets_id: assets_id, name: name, poster_image_url: poster_img_url,provider_id: provider_id)) } } SwiftLoading().hideLoading() }else{ SwiftLoading().hideLoading() } }) } } 

从资产表中的服务器数据存储中检索数据。

然后在CollectionViewCell中显示assetsTable数据。

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) as! HomeVideoCell cell.movieTitle.text = list.name cell.imageView.image = list.image return cell } 

我的问题是collectionViewCell数据与以前的assetsTable数据重复,并没有显示在CollectionView中的正确数据。

在这里输入图像说明

我的tableViewCell显示(Action,Drama)标签和My CollectionViewCell显示电影名称和电影图像。 我从服务器检索CollectionViewCell的数据,但CollectionViewCell没有显示相关数据。

在HomeVideoCell子类中清理prepareforreuse中的数据

 override func prepareForReuse() { super.prepareForReuse() self.movieTitle.text = "" self.imageView.image = nil }