如何在查看 UITableView 时重新加载它
当我将 UITableView 作为可见视图控制器的一部分时,如何重新加载它以便我正在查看的数据更改为新数据。 在我滚动数据之前,仅调用重新加载似乎不会刷新数据。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
调用
reloadData
方法在调用该方法后立即刷新数据。 它不会等待表格滚动。 确保在调用reloadData
之前更改数据源(数组或字典或保存值的位置)。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 callreloadData
.您是否正在从主线程刷新数据? 如果是这样,您需要使用以下方法调用 reloadData 方法:
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
因此,对于 tableView 来说,它会为:
[tableView PerformSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
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];
只是2013年的更新,你应该还可以重新加载数据,只要你使用
GCD太棒了!
Just a 2013 update, you should also be able to reload the data, just as long as you use
GCD is awesome!
以下代码可帮助您在查看时重新加载表:
The following code help you to reload table while you looking that: