如何将Prefs的值数据从视图控制器传递到里面的表格视图单元与SWIFT 3?
在Home.swift中 ,
我编写数据传递的代码。 这是代码。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let mainThemeList = mainHomeThemeTable[(indexPath as NSIndexPath).row] DispatchQueue.main.async { self.prefs.set(mainThemeList.main_associated_url, forKey: "associated_home_url") self.prefs.set(mainThemeList.main_name, forKey: "associated_name") } let cell = tableView.dequeueReusableCell(withIdentifier: "homecell") as! HomeCategoryRowCell DispatchQueue.main.async { cell.categoryTitle.text = mainThemeList.main_name cell.mainAssociatedURL.text = mainThemeList.main_associated_url debugPrint("Sandy Name:::::\(mainThemeList.main_name)") debugPrint("Sandy URL:::::::\(mainThemeList.main_associated_url)") cell.collectionView.reloadData() } return cell } <br>
debugging结果是:
"Sandy Name:::::Action" "Sandy URL:::::::search/filters?collections=1,2" "Sandy Name:::::Drama" "Sandy URL:::::::search/filters?collections=1" "Sandy Name:::::lastest Videos" "Sandy URL:::::::search/filters?collections=1,2" "Sandy Name:::::Breaking News" "Sandy URL:::::::search/filters?collections=3"
在HomeCollectionViewCell.swift中 ,
func getAssetsData(){ SwiftLoading().showLoading() debugPrint("Call Assests") if Reachability().isInternetAvailable() == true { associated_url = prefs.value(forKey: "associated_home_url") as! String! debugPrint("MP URL :::\(associated_url)") print("MP NAME::::\(UserDefaults.standard.value(forKey: "associated_name")!)") } }
当我打印MP URL时,结果只显示“ 动作和戏剧 ”类别。
不显示其他最新影片,突发新闻 。
我写错了什么?