Reputation: 809
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 ?
Upvotes: 0
Views: 953
Reputation: 1705
In addition to @StefanArentz answer
For Swift 3:
DispatchQueue.main.async {
// code to reload collection view
}
Upvotes: 1
Reputation: 316
What happens is that code is probably run on a secondary thread. Any UI changes you make should be made on the main thread. So try this:
dispatch_async(dispatch_get_main_queue()){
// reload your collection view here
})
Upvotes: 1
Reputation: 34935
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()
})
}
Upvotes: 3