I have a function that connects to the internet and then refreshes the cells in the table.
My function is:
- (void) updateMethod
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.name = @"Data request queue";
[queue addOperationWithBlock:^{
//neither of these delay the responsiveness of the table
[columnArrayBackground removeAllObjects];
[self getColumnDataBackground];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (int i=0; i < 6; i++) {
columnArray[i] = columnArrayBackground[i];
};
//THIS ONE LINE CAUSES DELAYS
[homeTable reloadData];
}];
}];
}
Everything is super speedy EXCEPT for [homeTable reloadData]. When I comment that out, I have quick response. When I uncomment it, my cell response lags sometimes by a few seconds!
My other reloadData calls do not delay my app. Am I not implementing NSOperationQueue correctly?
Remove the queues from your update method and leave only what updates the table. Under the action that refreshes your table add this code. Where the updateMethod is the code that updates the table. Only when you are back on the main thread do you reload the data. Hope this helps!
//perform on new thread to avoid the UI from freezing
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),
^{
//background thread code
[self performSelector:@selector(updatemethod:) withObject:nil];
dispatch_async(dispatch_get_main_queue(),
^{ //back on main thread
[self.tableView reloadData];
});});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With