0

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?

May Phyu
  • 895
  • 3
  • 16
  • 41
  • collectionView.reloadData() in custom cell of table view so easily reload with table view reload if not load then leave comment i will give you another suggetion And Code Into View DidAppear() – BHAVIK PANCHAL Jun 14 '17 at 11:56
  • Bro @BHAVIKPANCHAL, I add tableView.reloadData() in viewDidAppear. Now, when the app runs, the image shows immediately. But, when I go to other pages and goes back to Home, then image does not show and need to pull to refresh. – May Phyu Jun 15 '17 at 07:08
  • bro @BHAVIKPANCHAL, I updated my question. Could you please take a look bro ? – May Phyu Jun 16 '17 at 11:02
  • I think you can solve it this way https://stackoverflow.com/a/33364092/2893809 – Pablo Romeu Jun 20 '17 at 06:33

0 Answers0