UICollection View inside Table Cell does not show images in Swift 3

匿名 (未验证) 提交于 2019-12-03 01:27:01

问题:

I put UICollectionView inside table cell in Home page. Each category row has their contents image.
But, my problem is that when I run the app, the images under second row/second category do not show whenever I run the app.
The images will show after I click more button and it will goes to details UI. Then, I click on Back button and reach the Home page. At this time, the images shows properly.
I tried many codes but I don't know where it is wrong.

override func viewWillLayoutSubviews() {     super.viewWillLayoutSubviews()     tableView.reloadData()     self.tableView.reloadData()     self.tableView.layoutIfNeeded() }  override func viewDidAppear(_ animated: Bool) {     tableView.reloadData() }  override func viewWillAppear(_ animated: Bool) {     super.viewWillAppear(animated)      //getSearchWords()     DispatchQueue.main.async {         self.tableView.reloadData()      }     self.tableView.reloadData()     self.tableView.layoutIfNeeded() }      override func viewDidLoad() {       DispatchQueue.main.async {        self.tableView.reloadData()      } }  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {     // debugPrint("HOme Table View Cell")      let cell = tableView.dequeueReusableCell(withIdentifier: "homecell") as! HomeCategoryRowCell     let list = sections[(indexPath as NSIndexPath).row]      cell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)     cell.collectionViewOffset = self.storedOffsets[indexPath.row] ?? 0      DispatchQueue.main.async {         cell.categoryTitle.text = list.package_name         cell.mainAssociatedURL.text = list.package_url     }     cell.categoryTitle.font = UIFont.boldSystemFont(ofSize: 17.0)     cell.collectionView.tag = indexPath.row     cell.parentVC = self     cell.collectionView.reloadData()      return cell }   extension Home : UICollectionViewDelegate, UICollectionViewDataSource {  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {      return sections[collectionView.tag].packageTable.count }  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) as! HomeVideoCell          let list = sections[collectionView.tag].packageTable[indexPath.row]          if(list.poster_image_url != StringResource().posterURL){             let url = NSURL(string: list.poster_image_url)             do{                 if let url = url {                     _ = try Data(contentsOf:url as URL)                     poster_url = list.poster_image_url                 }        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!