如何设置单个数组或字典以在多个数据源中使用?

发布于 2024-07-30 20:03:13 字数 572 浏览 15 评论 0原文

我有多个 TableViewDatasources 需要根据某些属性显示同一池中的对象列表。 例如,

object.flag1 is set- it will show up in TableView1
object.flag2 is set- it will show up in TableView2

显而易见的方法是为每个 TableView 有单独的数组,但相同的对象可能出现在不同的数组中。 另外,我需要经常更新对象或通过同一数组访问所有对象。

如何设置单个字典或数组以将所有对象包含在一个结构中?


换句话说: 当表视图或选择发生更改时,应用程序需要使用新数据重新绘制 TableView。 应用程序必须访问对象池并使用迭代器搜索它们并访问每个对象及其属性。

我认为这是一项昂贵的操作,并且希望避免这种情况。 也许可以通过将对象的全局池制作为字典并将对象属性公开为字典字段来实现。

因此,我可以通过选择具有与特定条件匹配的字段的对象,以数据库的方式访问全局池字典,而不是迭代全局对象池。

有人知道这样做的任何例子吗?

I have multiple TableViewDatasources that need to display list of objects form same pool depending of certain property.
E.g.

object.flag1 is set- it will show up in TableView1
object.flag2 is set- it will show up in TableView2

The obvious way would be to have separate arrays for each TableView, But same object may appear in different arrays. Also I need to update objects very often or access all objects through same array.

How do I setup a single dictionary or array to have all objects in one structure?


To put it in another way:
When table view or selection changes, application need to redraw TableViews with the new data. Application have to access the pool of objects and search through them using iterator and accessing each object and its properties.

I think that this is an expensive operation and want to avoid that. Perhaps maybe by making a global pool of objects a dictionary and exposing objects properties as dictionary fields.

So instead of iterating global pool of objects I could access global pool Dicitonary in a manner of database by selecting objects that has fields that match particular criteria.

Anyone know any example of doing that?

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

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

发布评论

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

评论(2

梦情居士 2024-08-06 20:03:13

我倾向于创建充当数据源的代理集合。 这些代理在准备内容时从池中收集适当的对象。 在不知道池和子集的规模的情况下,考虑对其进行优化还为时过早。

I'd be inclined to create proxy collections which act as the data sources. These proxies gather the appropriate objects from the pool when they prepare their content. Without knowing the scale of your pool and subsets, it's too early to consider optimising that.

七度光 2024-08-06 20:03:13

这听起来像是一个过早优化的例子。 除非您管理数百个项目和/或导致重绘非常频繁地发生,否则即使迭代一百个对象并维护几个数组也不会产生足够的开销(无论是内存还是 CPU)而产生问题。

以简单的方式实现它,然后对其进行测量以确定是否确实存在性能问题。

This sounds like a case of premature optimization. Unless you are managing many hundreds of items and/or causing redraws to happen terribly often, iterating through even a hundred objects and maintaining a couple of arrays isn't going to incur enough overhead -- either memory or CPU -- to be problematic.

Implement it the easy way, then measure it to determine if you really have a performance problem.

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