Collection View inside Table does not load immediately in swift 3

╄→гoц情女王★ 提交于 2019-12-20 06:10:06

问题


I add one table view in Home View Controller.
Inside table view, I add Collection View.
An Image inside collection view at first time running the app. Then, goes to other links and come back to Home but image in the collection view does not show immediately until it scrolls at this second time.
After pulling the view several times, then Image appears.
In "Collection.swift" ,
In ViewDidLoad() ,

DispatchQueue.main.async {
    self.tableView.reloadData()
}

I also add in viewWillLayoutSubviews()

override func viewWillLayoutSubviews() {

    debugPrint("viewWillLayoutSubviews")
    DispatchQueue.main.async(execute: {() -> Void in
        self.tableView.reloadData()
        self.tableView.layoutIfNeeded()
    })   
}

and I also reload the Collection View

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let mainThemeList = mainHomeThemeTable[(indexPath as NSIndexPath).row]
    self.prefs.set(mainThemeList.main_associated_url, forKey: "associated_home_url")
    let cell = tableView.dequeueReusableCell(withIdentifier: "homecell") as! HomeCategoryRowCell

    DispatchQueue.main.async {
        cell.categoryTitle.text = mainThemeList.main_name
        cell.mainAssociatedURL.text = mainThemeList.main_associated_url
        cell.categoryTitle.font = UIFont.boldSystemFont(ofSize: 17.0)
        cell.collectionView.reloadData()

    }

    return cell
}



In Table View Cell (CollectionCell.swift) file ,

override func awakeFromNib() {
   self.collectionView.reloadData()
   self.collectionView.setNeedsLayout()
   self.collectionView.layoutIfNeeded() } 


override func layoutSubviews() {
    super.layoutSubviews()
     self.collectionView.reloadData()
     self.collectionView.setNeedsLayout()
     self.collectionView.layoutIfNeeded()


}

How can I do to load and show immediately in swift 3? Can anyone help me?

来源:https://stackoverflow.com/questions/44541403/collection-view-inside-table-does-not-load-immediately-in-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!