How to Reload a UITableView While I am Looking at

2019-01-22 06:23发布

When I have a UITableView as part of the visible view controller, how can I reload it so that the data I am looking at changes to the new data. Just calling reload doesn't seem to refresh the data until I scroll it.

4条回答
Ridiculous、
2楼-- · 2019-01-22 07:03

Just a 2013 update, you should also be able to reload the data, just as long as you use

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});

GCD is awesome!

查看更多
祖国的老花朵
3楼-- · 2019-01-22 07:05

Are you refreshing the data off the main thread? If so, you need to call the reloadData method using the following method:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

So for a tableView it would be:

[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

查看更多
孤傲高冷的网名
4楼-- · 2019-01-22 07:10

The following code help you to reload table while you looking that:

[self.tableView reloadData];
查看更多
Luminary・发光体
5楼-- · 2019-01-22 07:12

Calling the reloadData method refreshes the data as soon as the method is called. It does not wait for the table to be scrolled. Make sure the data source (array or dictionary or wherever you've saved the values) is changed before you call reloadData.

查看更多
登录 后发表回答