I am adding one table view to the Home View Controller.
Inside the table view, I add a Collection View.
The image inside the collection launches the application for the first time. Then go to other links and return to the house, but the image in the collection view does not appear immediately until it scrolls a second time.
By pulling the image several times, the image appears.
In " Collection.swift ",
In ViewDidLoad () ,
DispatchQueue.main.async { self.tableView.reloadData() }
I also add to 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 the Table Table Cell Element ( CollectionCell.swift ),
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 download and show right away in swift 3? Can anybody help me?
May Phyu Jun 14 '17 at 9:56 on 2017-06-14 09:56
source share