Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
I parse JSON according to page number and display the response in an UITableView. I calculate the page number like this
Code:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    if(self.orderListTable.contentOffset.y >= (self.orderListTable.contentSize.height - self.orderListTable.frame.size.height)) {
        NSInteger pageNumber = scrollView.contentOffset.y /  (scrollView.contentSize.height - scrollView.frame.size.height);
        NSLog(@"END %ld", (long)pageNumber);
        self.scrollPage = [NSString stringWithFormat:@"%ld", (long)pageNumber];
        if (pageNumber == 0) {
            [self.orders removeAllObjects];
            [self getTheOrderList:self.selectedOrderType page:self.scrollPage];
        } else {
            if (self.previousScrollPage == pageNumber) {
                return;
            } else {
                [self getTheOrderList:self.selectedOrderType page:self.scrollPage];
            }
        }
        
        self.previousScrollPage = pageNumber;
    }
}
But in this calculation sometimes i get wrong page number. When the page number increase then the calculation gives a wrong result. (e.g: page number 3 from 5. It skips the 4). Is there any different way to make a paging with UITableView
 
Why not us the the cellWillDisplay delegate method and check if the indexPath == last item in your datasource.
 
Why not us the the cellWillDisplay delegate method and check if the indexPath == last item in your datasource.
Thank u for reply. I tried to do this way also but it triggers the method 3 or 4 times in a row. So i checked if tableview stopped scrolling but this time it never invokes the method inside willDisplayCell.
Code:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == self.orders.count - 1) {
        if (self.isDecelerated) {
            NSInteger counter = [self.scrollPage integerValue];
            counter += 1;
            self.scrollPage = [NSString stringWithFormat:@"%ld", (long) counter];
            [self getTheOrderList:self.selectedOrderType page:self.scrollPage];
            NSLog(@"DIPTEYIZ");
        }
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
self.isDecelerated = YES;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (!decelerate) {
        self.isDecelerated = YES;
    }
}

What is wrong here ?
 
What do you mean called 3 or 4 times? The method willDisplayCell is always called when the tableView scrolls. Is willDIsplayCell not getting called at all?? If that is the case, then it sounds like you haven't set the delegate parameter for the tableView.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.