Reputation: 4882
I ran into this weird behavior of a UITableView
.
I'm fetching some records from CloudKit in my app. I have set up a dedicated subclass of NSObject
to handle all this, and anytime it receives a record, it adds the record to my model array and then tells its delegate it has received something. The delegate then reloads the tableView
.
func cloudKitFetchedRecord(identifier: NSString) {
if identifier.isEqualToString("getAllProfiles") {
self.tableView.reloadData()
}
}
This all works. Except for the fact that after i call reloadData
, nothing happens for a while. It takes about 10-20 seconds for the table to actually reload. Weirdly, it also reloads when I tap the screen, but when I fire reloadData
nothing happens.
I have checked my entire application, put in breakpoints everywhere, but the app isn't doing anything while it delays the reload. I also cleaned the project, cleaned the build folder, pretty much did everything I could come up with but it keeps doing this.
Did anyone else run into this behavior, or does anyone know anything on how to solve it?
Any comments would be highly appreciated
Upvotes: 1
Views: 672
Reputation: 3960
I think your delegate
call happens in background, So all you need to do is to call reloadData
function in Main Thread
dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})
Upvotes: 3
Reputation:
Run your reloadData method on the main thread:
dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})
Upvotes: 6