iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何使用swift3在TableViewCell中的CollectionViewCell中动态显示服务器中的数据?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我从TableViewCell获取了我的json链接数据,然后从服务器检索该数据并在collectView中显示相关的TableViewCell数据. 如何在swift3中显示这些数据?请帮帮我. 我从TableViewCell获得了url链接(mainThemeList.main_associated_url,main_Name). func tableView(_ tableView: UIT
我从TableViewCell获取了我的json链接数据,然后从服务器检索该数据并在collectView中显示相关的TableViewCell数据.
如何在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
    }

然后数据来自Server的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()

                }
            })
        }
    }

从assetsTable中的服务器数据存储中检索数据.

然后在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中没有显示正确的数据.

ios – 如何使用swift3在TableViewCell中的CollectionViewCell中动态显示服务器中的数据?

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

解决方法

在HomeVideoCell子类中,准备好在prepareforreuse中清理数据

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

大佬总结

以上是大佬教程为你收集整理的ios – 如何使用swift3在TableViewCell中的CollectionViewCell中动态显示服务器中的数据?全部内容,希望文章能够帮你解决ios – 如何使用swift3在TableViewCell中的CollectionViewCell中动态显示服务器中的数据?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。