0

I have a UITableView that is populated with content that can be tagged/bookmarked by a user. My app successfully sends the bookmark info to a server-side database when content is bookmarked. I'm trying to figure the most efficient way to display a bookmarked image in the respective cell if the content has already been bookmarked by the user.

For example, a user taps a cell's bookmark and the bookmark image displays a different image to verify the bookmark. The bookmark info is sent to the database. This already works

Here's where I need help...

When the user opens the app again, the UITableView is re-populated with data. If the cell contains content that has been bookmarked, I need to display the bookmarked image in the cell. Right now, I have a database query in ViewDidLoad that pulls the user's bookmarks. The only implementation I can think of is searching through the query data in cellForRowAtIndexPath. However, I know this is going to affect my scrolling performance. Is there a better way to do this?

4

1 回答 1

0

如果您没有数百万个书签,那么检查每个书签上的标记cellForRowAtIndexPath应该不会对性能产生太大影响。

以我的经验,表格视图滚动非常高效,并且仍然有足够的处理器时间来做其他事情。对索引处的值进行简单检查应该不会对其产生太大影响。也许解决它的最佳方法是解析您的查询结果并创建一个专用的 NSArray,每个索引处只有 YES/NO 标志,您可以在此期间检查cellForRowAtIndexPath以决定是否显示书签指示器。

如果您确实需要尽可能快地获得速度,您可以viewDidLoad 在每个特定索引处创建一个具有 0/1 值的 C 数组并访问它array[index]。这消除了 NSArray 中可能存在的任何额外开销。但同样 - 我的经验表明,对于这些用途,开销是最小的。

于 2012-05-30T14:59:51.493 回答