在UITableView中进行分页的最佳方法 [英] Best way to do paging in UITableView

查看:158
本文介绍了在UITableView中进行分页的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个房地产应用程序。应用程序在用户填写表单(最小房间,价格等)后查询数据源服务器,并获取具有特定键/值对的json字符串(属性名称,属性地址,经度/纬度,价格等等... )。

I'm working on a real estate app. The app query a datafeed server after user fill in a form (min rooms, price and so on) and it gets a json string with specific key/value pairs (property name,property address,longitude/latitude,price,etc...).

我正在尝试做的是允许用户在UITableView中浏览列表,即使Feed包含很长的项目列表而不必重载用户iphone(在查询完成之前,返回的项目数量是未知的,因此应用程序需要处理此问题)...您建议我进行分页?

What I'm trying to do is allowing the user to browse the listing in a UITableView even if the feed contains a long list of items without having to overload the user iphone (the returned items count is not known before the query is done, so the app need to handle this)...What would you suggest me for paging ?

Thx提前,

Stephane

推荐答案

如果你的 tableView:cellForRowAtIndexPath:使用 dequeueReusableCellWithIdentifier:正确编写方法(并且你不使用 tableView:heightForRowAtIndexPath :,或者它非常快),UITableView应该能够处理数千行而不会使设备过载。您只需关注原始数据的存储。

If your tableView:cellForRowAtIndexPath: method is written correctly using dequeueReusableCellWithIdentifier: (and you don't use tableView:heightForRowAtIndexPath:, or it is very fast), UITableView should be able to handle thousands of rows without overloading the device. You just need to be concerned with the storage of your raw data.

至于在查询完成之前不知道行数的问题,这很容易解决。当您从查询中收到更多行时,只需使用UITableView的 insertRowsAtIndexPaths:withRowAnimation:来通知表视图有更多行可用(并确保您的 tableView:numberOfRowsInSection: tableView:cellForRowAtIndexPath:然后将反映这些新行。)

As for your problem of not knowing the number of rows until the query is complete, that is easy enough to work around. As you receive more rows from the query, just use UITableView's insertRowsAtIndexPaths:withRowAnimation: to inform the table view that more rows are available (and be sure that your tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath: will then reflect these new rows).

如果您还想等到用户在继续查询之前滚动到当前列表的末尾,请注意UITableView是UIScrollView的子类,UITableViewDelegate实现UIScrollViewDelegate。所以只需在你的UITableViewDelegate上使用 scrollViewDidScroll:来知道用户何时滚动,然后检查表视图的 contentOffset 以确定是否他们向下滚动的距离足以让您想要加载更多数据。

If you are also wanting to wait until the user scrolls to the end of the current list before continuing the query, note that UITableView is a subclass of UIScrollView and UITableViewDelegate implements UIScrollViewDelegate. So just use scrollViewDidScroll: on your UITableViewDelegate to know when the user scrolls and then check the table view's contentOffset to determine if they've scrolled down far enough that you want to load more data.

这篇关于在UITableView中进行分页的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆