I have a ViewController and it has a PageMenu in it as MainCollectionViewController.

When you first load the application, data is loaded from the server, and should be displayed in PageMenu. How to display data immediately when you first download the application?

Here in PageMenu is empty.

But after the second boot, everything works.

  • We must look code - markov
  • Most likely you need to update the view, but you need to look at the code. - Vitali Eller
  • Laid out the project here github.com/zhanswift/HalykNews - Zhan
  • does not work in xcode8 - Max Mikheyenko
  • Project on Swift 2.3 and Xcode 7.3.1 - Zhan

2 answers 2

Get familiar with streams. All UIKit is not thread-safe and all work with the classes of this library should be carried out on the main thread. In your case, this is the management refreshControl, activityIndicator, update collectionView.

GCD can help you with this:

dispatch_async(dispatch_get_main_queue(), { }) 

Or NSOperation:

 NSOperationQueue.mainQueue().addOperationWithBlock() { } 

    Data does not always have time to load before the show. It is required to add to the function that pulls the data from the server, the Completion Handler .