0

I have the following code in ViewControllerA

let layout = UICollectionViewFlowLayout()
let controller = ViewControllerB (collectionViewLayout: layout)

controller.contentData = self.users_cities[indexPath.row].content
self.navigationController?.pushViewController(controller, animated: true)

Now when let controller = ViewControllerB (collectionViewLayout: layout) is called, the viewDidLoad method of ViewControllerB is executed and the UI is setup for ViewControllerB. The problem is that this makes the UI of ViewControllerA freeze for a few seconds before ViewControllerB is pushed. Is there a different way of doing this in order to avoid this problem? The natural solution would be to run that on the background thread, but as far as I know, you shouldn't setup views on the background thread.

Alk
  • 5,215
  • 8
  • 47
  • 116
  • Maybe you have some heavy lifting happening on the main thread in ViewControllerB's ViewDidLoad and ViewWillLoad functions. – DanielEdrisian Jul 14 '16 at 18:36
  • Maybe have those run asynchronously in another thread? – DanielEdrisian Jul 14 '16 at 18:37
  • @SahandTheGreat I do, I do a lot of view creation and assigning constraints, but I thought that you cannot run anything related to `UIViews` on background threads? – Alk Jul 14 '16 at 19:12

0 Answers0