-[UITableView reloadData] shows changes only after scrolling
-
06-07-2021 - |
Question
I update the UITableView
on timer. I change data in array, then call -[UITableView reloadData]
. But nothing is changed until I scroll the table or switch tabs in the tab bar. What's happening? How can I avoid this?
Solution
Don't reload table on not main thread
OTHER TIPS
The problem was in that:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
self.newList = [self loadData];
[self.delegate list:self didUpdate:self.newList];
});
Delegate call was on the background thread. If you want to update UI you should do in on the main thread.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
self.newList = [self loadData];
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate list:self didUpdate:self.newList];
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow