Ios 如何使用swift3在TableViewCell的CollectionViewCell中动态显示来自服务器的数据?
我从TableViewCell获取json链接数据,然后从服务器检索该数据,并在collectionView中显示相关的TableViewCell数据。 如何在swift3中显示此数据?请帮帮我 我从TableViewCell获得了url链接(mainThemeList.main\u关联的\u url,main\u名称)Ios 如何使用swift3在TableViewCell的CollectionViewCell中动态显示来自服务器的数据?,ios,iphone,xcode,swift3,tableviewcell,Ios,Iphone,Xcode,Swift3,Tableviewcell,我从TableViewCell获取json链接数据,然后从服务器检索该数据,并在collectionView中显示相关的TableViewCell数据。 如何在swift3中显示此数据?请帮帮我 我从TableViewCell获得了url链接(mainThemeList.main\u关联的\u url,main\u名称) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITabl
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()
}
})
}
}
从AssetTable中的服务器数据存储中检索数据
然后AssetTable数据显示在CollectionViewCell中
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数据与以前的AssetTable数据重复,并且没有在CollectionView中显示正确的数据
My tableViewCell show(动作、戏剧)标签和My CollectionViewCell show电影名称和电影图像。我从服务器检索CollectionViewCell的数据,但CollectionViewCell未显示相关数据 在HomeVideoCell子类中清理prepareforeuse中的数据
override func prepareForReuse() {
super.prepareForReuse()
self.movieTitle.text = ""
self.imageView.image = nil
}
在HomeVideoCell子类中清理prepareforeuse中的数据
override func prepareForReuse() {
super.prepareForReuse()
self.movieTitle.text = ""
self.imageView.image = nil
}
编辑您的问题,并通过添加更多内容使其更清楚地理解场景。因此,基本上您尝试在tableViewCell中使用集合视图。您的问题与表视图单元格的出列有关。您必须为每个tableView单元格的集合视图设置单独的数据,并在tableView的CellForRowatinex中传递需要显示的数据。每个单元格都将包含/存储/拥有自己的集合视图数据。在tableViewCell的类中创建和排列字典,并在cellForRowAtIndexPath中传递从webservice检索到的tableView数据。我的问题是,我可能不知道服务器中有多少tableViewCell数据。它的tableViewCell数据来自服务器数据是动态数据。这就是为什么在我的代码中,对于未知数量数据的单独CollectionView是不合适的@Pramodkumary您必须从后端获取每个类别的数据,如{“Action”:[{“title”:“黑暗骑士”、“拇指”:“拇指的url”},{“title”:“教父”、“拇指”:“拇指的url”}]“戏剧”:[{“title”:“Malgudi天”、“拇指的url”:“拇指的url”}等等。。然后,您必须根据此字典的总键(“Action”、“戏剧”)在表视图中创建总单元格。然后,您必须将动作数据发送到动作单元的collectionView,并将戏剧数据发送到戏剧单元的collectionView编辑您的问题,并通过添加更多内容使其更清楚地理解场景。因此,基本上您尝试在tableViewCell中使用集合视图。您的问题与表视图单元格的出列有关。您必须为每个tableView单元格的集合视图设置单独的数据,并在tableView的CellForRowatinex中传递需要显示的数据。每个单元格都将包含/存储/拥有自己的集合视图数据。在tableViewCell的类中创建和排列字典,并在cellForRowAtIndexPath中传递从webservice检索到的tableView数据。我的问题是,我可能不知道服务器中有多少tableViewCell数据。它的tableViewCell数据来自服务器数据是动态数据。这就是为什么在我的代码中,对于未知数量数据的单独CollectionView是不合适的@Pramodkumary您必须从后端获取每个类别的数据,如{“Action”:[{“title”:“黑暗骑士”、“拇指”:“拇指的url”},{“title”:“教父”、“拇指”:“拇指的url”}]“戏剧”:[{“title”:“Malgudi天”、“拇指的url”:“拇指的url”}等等。。然后,您必须根据此字典的总键(“Action”、“戏剧”)在表视图中创建总单元格。然后,您必须将动作数据发送到动作单元的collectionView,并将戏剧数据发送到戏剧单元的collectionView。我无法在HomeVideoCell.swift中调用该单元。怎么打电话@MeghsDhameliyaI无法在HomeVideoCell.swift中呼叫手机。怎么打电话@梅格斯达梅利亚