如何在查看 UITableView 时重新加载它

发布于 2024-07-15 23:51:12 字数 89 浏览 6 评论 0原文

当我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风为裳 2024-07-22 23:51:12

调用 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 call reloadData.

找回味觉 2024-07-22 23:51:12

您是否正在从主线程刷新数据? 如果是这样,您需要使用以下方法调用 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];

刘备忘录 2024-07-22 23:51:12

只是2013年的更新,你应该还可以重新加载数据,只要你使用

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

GCD太棒了!

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!

空城旧梦 2024-07-22 23:51:12

以下代码可帮助您在查看时重新加载表:

[self.tableView reloadData];

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

[self.tableView reloadData];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文