Take the 2-minute tour ×

I am working on a project in which at first web service call we are getting some 20 number of data which we are loading to table view and once we start scrolling up for view when it reaches 20 number we need to call service for next 20 no's, like facebook does.

This we need to do for each next 20 until data ends and load to tableview from last data of previous call and we can see all data when we scroll down for previous data. And need to show "more data loading" when we scroll up table after 20th cell.

Please Help me !


share|improve this question

2 Answers 2

up vote 1 down vote accepted

Simply create private offset variable and increase it each time on success loading.
Let's think this is your web service that gets GET parameters:


Your Objective C code will look like this:

In header file:

@interface YourClass
   uint _offset;

In implementation file:

- (void)viewDidLoad {
    _offset = 0;

- (void)loadFromServer {
    NSString *stringURL = [NSString stringWithFormat:@"%@/%@", kServer, _offset];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:stringURL]];
    NSString *params = [NSString stringWithFormat:@"offset=%i&amount=20", _offset];
    NSData *postData = [params dataUsingEncoding:NSUTF8StringEncoding];

    request.HTTPMethod = @"GET";
    request.HTTPBody = postData;

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    if (error) {
    }else {
        NSError *jsonError;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&jsonError];

        _offset += 20;


share|improve this answer
this only for getting server response....and this is not the issue the is with table view, means while scrolling up when 21st row will come at time we need to call the service... –  Rahul Nov 13 '12 at 9:35
You could read this thread: stackoverflow.com/questions/4610299/… or take a look at this: github.com/shiki/STableViewController –  pbibergal Nov 13 '12 at 9:47
thanks, pbibergal –  Rahul Nov 26 '12 at 9:56

Add UITableViewDelegate method willDisplayCell

    int count = [yourDataSource count];;

    if(indexPath.row == count - 1) // If going to display last row available in your source
        //totalPageCount is the total pages available in the server. This needs to be stored on initial server call
        //currentIndex is the index of page last retreived from server. This needs to be incremented every time new page is retreived.
        if(currentIndex <= totalPageCount) 
            [self getContentsForPage:currentIndex];
            self.tableView.tableFooterView = nil; //You can add an activity indicator in tableview's footer in viewDidLoad to show a loading status to user.

share|improve this answer

Your Answer


