views:

29

answers:

2

Hi,

I have a table view with one section. I pull the data down from the internet in small chunks asynchronously in the background. The problem I have is I don't know how many records there will be in total. When the web service stops returning data I know I have them all, in some cases the rows might be infinite.

The method:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

is understandably called once at the beginning of view load, at this point I don't know how big my section is going to be. Any ideas on how best to approach this problem? Can I set the section size anywhere after this method has been called?

+5  A: 

You can make the tableview reload it's data, call

[tableView reloadData];

...and it will ask the datasource about number of rows etc again.

epatel
Will that make the view reload, starting the scroll at the top again?
Dominic Godin
Just tried it, looks like it doesn't so this might work. Thanks.
Dominic Godin
A: 

You say data is pulled in chunks - so only update your table in chunks.

Each time a chunk is downloaded, reload the table. This way, you know how many rows there are after each chunk is finished.

Example:

  1. App loads (no data)
  2. Chunk downloads
    • Put results into array
    • 6 rows in array, return [array count] in number of rows in section method
    • reload table
  3. repeat step 2 until done.

Reload data does not reset the scroll position.

Jasarien