iPhone 桌面视图分页
首先,请相信我,当我说我确实首先搜索了这个答案......很多。我找到了很多例子,但没有一个表现与我需要的相似。虽然我可能使用了错误的关键词进行搜索,但我不这么认为。
这是我的问题:
我有一个表视图,该视图由返回大量数据的查询填充。该数据包含餐厅列表、价格评级和 ID。但数据库中的餐馆太多,以至于它会填满内存并导致应用程序崩溃。 (我假设这就是正在发生的事情,因为如果查询受到限制,代码就可以正常工作,并且始终在其他页面上工作,我查询没有返回那么多数据的内容。)
我想要做什么正在为此页面的应用程序表视图进行分页。我不知道如何使用“显示更多”方法,或滚动到底部时自动加载,只是因为如果向下滚动到列表末尾,您仍然会遇到相同的问题:填充内存。有没有一种方法可以进行类似网络的分页,其中(如果它们不在第一页上)它们在顶部有一个“上一页”单元格,并且(如果不在最后一页上)在底部有一个“下一页”单元格?这些必须清除当前视图中的单元格并删除数据,因此我们不仅仅是添加会导致相同问题的数据,然后执行新的查询来填充单元格。
当然,我并不期望有人坐在这里为我编写所有代码。我需要的主要部分是如何设置下一个和上一个单元格的单元格。之后我应该能够弄清楚其余的事情,但我不知道如何从当前表视图中清除数据。
感谢您的任何帮助或建议。
First, please believe me when I say I did search for this answer first... a lot. I found many examples, but none performing similarly to what I need. Though I could have been searching using the wrong key words, I don't believe so.
Here is my issue:
I have a table view being populated by a query that is returning a huge amount of data. The data is for a list of restaurants, a price rating, and id. But there are so many restaurants in the database that it fills memory and crashes the app most time. (I am assuming this is what is going on, as the code works just fine if the query is limited, and has always worked on other pages I query things that don't have as much data returned.)
What I would like to do is make pagination for the application's table view for this page. I don't see how I could use the "Show More" method, or the auto load when scrolled to the bottom, simply because if you scroll down to the end of the list, you will still have the same issue: filling memory. Is there a way to do web-like pagination where (if they are not on the first page) they have a "Previous" cell at the top and (if not on the last page) a "Next" cell at the bottom? These would have to clear the cells out in the current view and drop the data so we're not just adding data which would cause the same issue, then do a new query to populate the cells.
Of course, I do not expect someone to sit here and write all that code for me. The main part I would need is just how to set up the cells for the next and previous cells. I should be able to figure the rest out after that, but I don't know how to go about clearing the data from the current table view.
Thanks for any help or suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以使用显示更多方法或滚动时加载,你说问题是你仍然加载一堆所有数据并且你会耗尽内存,但你可以避免这种情况......一个选择是,保存到磁盘或只是释放未在表视图上显示的数据,您可以使用 UITableView 的 indexPathsForVisibleRows 方法来查看哪些单元格可见,通过该信息您应该知道可以安全地释放哪些数据...您可以执行此操作当您收到内存警告时,或者也许当单元格滚动离开屏幕时(由你决定)...
希望这对
丹尼尔有帮助
I think you can do with a show more method or loading as you scroll, you say the problem is that you still load a bunch all the data and youll run out of memory, but you can avoid that... One option is, save to disk or just release data that isnt being shown on the table view, you can use indexPathsForVisibleRows method of UITableView to see which cells are visible, and with that info you should know which data you can safely release... You can do this either when you receive memory warnings, or maybe as cells are scrolled off the screen (up to you)...
Hope this helps
Daniel