views:

303

answers:

2

Hi guys,

I am working on an iphone application. Application loads plenty of records from a webservice into table view controller. I would like to load 25 records initially and remaining in 25 batch on clicking something like "Load 25 more" at the end of the table view.

Any help would be grealy appreciated.

Thanks

A: 

I do almost the same in my application, getting 50 first records from webservice. As a table footer I have a view with next/previous buttons, that when pressed launch a fetching request for next/previous 50 results. After fetch request is processed I call viewWillAppear:animated: for my view controller and inside to [self.tableView reloadData], so these results show up in the same table view. Of cause I'm keeping the data each time only for presented results, but it depends on your needs.

Hope this helps

Nava Carmon
When I fetch another 25 records and call viewWillAppear to reload data, will they append to the first 25 or replace them?
Leo
In my case it replaces them, since I use the same array, so before i parse next 50 results I clean the array. So it doesn't append results, rather overrides them
Nava Carmon
Thanks for your reply. Really appreciate that. Do you have any idea how can we achieve the appending?
Leo
You can append data to your existing results array. Just don't forget to update the number of rows accordingly, since reloadData method rebuilds the table. Also, you probably will want to present next 25 results, so you should keep a 0-based currentPage variable and update it accordingly each time you go forward/back. In viewWillAppear and a function: [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];where a row will be currentPage*NUM_ROWS_IN_PAGE (25 in your case).
Nava Carmon
Thank you very much for your reply. Certainly pointing to the right direction.
Leo
i think that scrolling to the top of your next page will give the feeling that it's the next page, in opposite to leaving the table in the same position. Say you're on 10th row and now you pressed the next button. you will stay on 10th row and will not know that you've brought fresh results. BTW, you can append data w/o stretching the table, i mean to leave the table with the same 25 rows, just present there relevant data from your array, so the user will not require to scroll forever... just a thought
Nava Carmon
+1  A: 

Just put a button connected to an Event in your table footer. When the button is clicked, append the next 25 results to your already existing array of items.

After that, just do a [self.tableView setNeedsDisplay]. I use that to let my table know I have extra data in the table. By using that, there is no need to scroll to the right line in the table, because it keeps its original position.

Also, why call the viewDidAppear method, this seems wrong to me, because (ofcourse) the view already appeared and all declerations and assignments you do there are re-done. Just put the stuff you need to be done while viewing the view AND when you are appending data in a seperate method and put call that method from your button-press event and from the viewDidAppear event.

Wim Haanstra
Thank you very much for your reply. Sounds like a good approach. Exactly what I'm looking for. I'll give it a try and update you when done.
Leo
Ow, also, for appending an array to your already existing array:[yourCurrentArray addObjectsFromArray:newArray];The newArray can contain (for example) newly fetched results.
Wim Haanstra
Brilliant!!! Thanks
Leo