3

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...).

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 in advance,

Stephane

Echilon
  • 10,064
  • 33
  • 131
  • 217
Stephane
  • 4,978
  • 9
  • 51
  • 86
  • 1
    best implementation I found on paging: http://www.lwxted.com/blog/2012/smart-data-loading-table-views/ – Firdous Oct 02 '12 at 09:54

3 Answers3

11

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.

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).

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.

Anomie
  • 92,546
  • 13
  • 126
  • 145
0

Well if some one is interested in paging using buttons then I found this post usefull http://www.mindyourcode.com/ios/iphone/pagination-in-uitableview-with-next-previous-buttons/ may be for some others it would be helpful

Mashhadi
  • 3,004
  • 3
  • 46
  • 80
0

whats the average number of items people can have? 10, 100, 1000? Does it have images or just data? Generally, I'd vote for not having any pagination - just load more as you scroll down, and try to load all of them at the very first time if there are not too many. You can also cache them on the device and add "pull to refresh" functionality, this way you improve offline experience.

TommyG
  • 4,145
  • 10
  • 42
  • 66
  • 10 items per page if it was on a webpage and it has images to display in the table cells – Stephane Aug 31 '11 at 20:41
  • As said I don't know the total listing in advance. For example, a particular search could have 110 items, showing 10 items per "page" it makes 11 "page" to show – Stephane Aug 31 '11 at 23:41
  • 10 items per page if it was on a webpage and it has images to display in the table cells – Stephane Sep 01 '11 at 12:15
  • In that case I would just load everything in one table, and with no pagination. – TommyG Sep 01 '11 at 12:50