cedric petetin cedric petetin - 7 months ago 17
Swift Question

Swift : collectionView takes too long to display

I am developing an iOS application in Swift.

I display data from database inside a collectionview but it takes too much time to appear on screen.
Surely a thread problem because on Xcode console, I can see data being displayed 20 seconds before it appears on the screen. Here is my code :
https://github.com/ProjetCedibo/projet/blob/master/Projet-L3-master/appli/SJEPG/SJEPG/CenterViewController.swift

How can I make the collectionView being displayed faster ?

Answer

If this happens, it means you are making UI changes from a thread other than the main thread. Try this:

func refresh() {
    dispatch_async(dispatch_get_main_queue(), {
        self.eventsCollection.reloadData()
    })
}
Comments