使 UITableView 内容无效

发布于 2024-09-03 22:25:45 字数 344 浏览 3 评论 0原文

我有一个带有多个 UITableViewController 的应用程序。 现在,用户可以更改“数据源”。在这种情况下,我需要使相关 UITableView 中的数据无效(重置)。

我发现,我可以使用 NSNotificationCenter 并将这些控制器作为观察者添加到数据源更改时生成的事件。

问题是,如何重置基础表?当然,我可以设置一些布尔标志,并在 viewWillAppear 或 viewDidAppear 中调用 UITableView:reloadData,但我想知道是否有更干净的方法来做到这一点。

或者也许我完全没有抓住要点,而且我完全不需要 NSNotificationCenter。 预先非常感谢您。

I have an application with several UITableViewControllers.
Now, the user is allowed to change "Data source". In that case I need to invalidate (reset) data in the relevant UITableViews.

I figured out, that I can use NSNotificationCenter and add these controllers as observers to events which will be generated when the data source changes.

The question is, how do I reset the underlying tables? I can, of course, set some boolean flag, and call UITableView:reloadData in viewWillAppear or viewDidAppear, but I was wondering, if there's a cleaner way of doing it.

Or perhaps I'm completely missing the point, and I don't need NSNotificationCenter altogether.
Thank you very much in advance.

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

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

发布评论

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

评论(1

江南烟雨〆相思醉 2024-09-10 22:25:46

问题是,如何重置
底层表?当然,我可以设置一些布尔标志

我不确定为什么你需要在这里使用标志。当您的视图控制器收到通知时,让它在通知处理程序中重新加载表。

如果您的 UITableView 附加到 NSFetchedResultsController,更新表格的工作方式会有所不同。是吗?

The question is, how do I reset the
underlying tables? I can, of course, set some boolean flag

I'm not sure why you need to use a flag here. When your view controller gets the notification, have it reload the table in the notification handler.

Updating your table will work a bit differently if your UITableView is attached to an NSFetchedResultsController. Is it?

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