简体   繁体   中英

Get data in batches & store it in NSMutableArray to display it in UITableView in iphone

How can I get the data from address book in batches of say 20 records at a time & display that 20 records in table view. When new 20 records are fetched , I want to add it in existing array & reload the data. How can I do this? Thanks

In the following delegate where you are setting your rows add one extra row

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return yourMutableArray.count+1;
}

The following delegate tells you that currently which cell is being created.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Under this you can add a check condition like

if(indexPath.row > yourMutableArray.count)
{

  // This means you are at the end of your table
  // Call your webservice here and append the next set of data into the yourMutableArray
  // You can also show an activity indicator over the extra cell here, Indicating the loading of new data
   [self performSelector:@selector(getDataFromWebservice) withObject:nil afterDelay:1.0];
}
else
{
  // Do your cell settings here
}

and somewhere in your code where you are checking for the success of your webserivce add the following line to reload the table

[yourTable reloadData];

Make sure, that you append the new data into your MutableArray, else table will show only the latest data from the webservice. Hope, this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM