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

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

概述我从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中没有显示正确的数据.

我的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中动态显示服务器中的数据?所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067477.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存