Reputation: 2941
I'm working on an app where I want to pull data from a remote web service and populate a UITableView. When I get new data I want the currently visible cells to remain and add the new data above it, much like most Twitter clients does. My load method currently looks like this:
- (void)loadPostsInBackground
{
NSURL *url = [NSURL URLWithString:@"[URL]"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id jsonObject) {
[self createPostsFromDict:jsonObject];
[self.refreshControl endRefreshing];
[self.tableView reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id jsonObject) {
NSLog(@"Received an HTTP %d", response.statusCode);
NSLog(@"The error was: %@", error);
}];
[operation start];
}
This works, but it updates the currently visible cells with the new data. So what I want is, get new data, add it above the currently visible cells (or stay at the currently visible cells). What is the best way to do this?
Note: I will require iOS6.
Upvotes: 1
Views: 1720
Reputation: 318954
Instead of calling reloadData on the table view. You should call insertRowsAtIndexPaths:withRowAnimation:. Do that after updating the data used by the table view's data source.
Upvotes: 2