我的数据源正在从 UITableView 下更改

发布于 2024-10-03 15:54:34 字数 640 浏览 7 评论 0原文

我有一个基于选项卡栏和从互联网检索的数据的应用程序。主选项卡显示地图,其他选项卡之一显示使用 UITableView 显示的地图中心点周围的事件。如果用户移动地图,然后移动到事件页面,我需要刷新表中显示的事件列表。为此,我请求 viewWillAppear:animated: 中的事件,当该事件完成(异步)时,我调用表视图的 reloadData 方法。

除非用户在选项卡之间快速点击(例如显示事件、移至地图、移动地图、移回事件、移回地图等),否则此操作效果非常好。在某些时候,当表视图尝试访问事件数据源(NSArray)时,它会被修改。

这是一个类似的问题:
如果在滚动期间更新数据源,UITableView 会崩溃

一该问题的解决方案描述了一个高层次的解决方案,这正是我想要的:在更新表时冻结数据源。然而,我不知道何时解冻数据源。问题是当表更新完成时我找不到任何通知方式。

有什么想法吗?如何在更新表时冻结数据源,然后在表更新完成后将其解冻?

I have an app based on a tab bar and data retrieved from the Internet. The main tab shows a map and one of the other tabs shows incidents around the center point of the map displayed using a UITableView. If the user moves the map and then moves to the incidents page, I need to refresh the list of incidents displayed in the table. To do this I request the incidents in viewWillAppear:animated: and when that completes (asynchronously) I call the table view's reloadData method.

This works beautifully unless the user taps between the tabs quickly (e.g. display incidents, move to map, move map, move back to incidents, move back to map, etc.). At some point the incidents data source (an NSArray) is modified while the table view is trying to access it.

Here is a question that is similar:
UITableView Crashes if Data Source Is Updated During Scrolling

One of the solutions for that question describes a solution at a high level that is exactly what I want: Freeze the data source while the table is being updated. The thing I can't figure out, however, is when to unfreeze the data source. The problem is I can't find any way to be notified when the table is done being updated.

Any ideas? How do I freeze the data source while the table is being updated and then unfreeze it once the table is done being updated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

忆沫 2024-10-10 15:54:34

虽然我真的很想在表视图完成访问数据源时收到通知,但我发现我的问题是由于从工作线程修改数据容器造成的。这个问题的答案让我找到了解决方案:

刷新 XML 数据并更新 UITableView

我现在要做的是在工作线程中填充一个单独的数组,然后在主线程上执行选择器以将更新的数据交换到表视图使用的数据容器中。

Although I'd really like to receive a notification when the table view is done accessing the data source, I found that my problem was due to modifying the data container from the work thread. The answer to this question led me to the solution:

Refreshing XML data and updating a UITableView

What I do now is fill a separate array in the worker thread and then perform a selector on the main thread to swap the updated data into the data container used by the table view.

祁梦 2024-10-10 15:54:34

问题是我找不到任何方法
表格完成后收到通知
正在更新。

我认为您可以假设通过检查 tableView:cellForRowAtIndexPath: 来查看最后一行是否已加载,数据已完成加载。

我没有测试过,只是根据API做一个假设

The problem is I can't find any way to
be notified when the table is done
being updated.

I think you can assume that the data is done being loaded by checking in tableView:cellForRowAtIndexPath: to see if the last row has been loaded.

I haven't tested it, just making an assumption based on the API

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