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
If your
tableView:cellForRowAtIndexPath:method is written correctly usingdequeueReusableCellWithIdentifier:(and you don’t usetableView: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 yourtableView:numberOfRowsInSection:andtableView: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’scontentOffsetto determine if they’ve scrolled down far enough that you want to load more data.