UITableView infinite scrolling

ios, ipad, iphone, objective-c

Solution

If you need to know when you hit the bottom of the UITableView, become it's delegate (because it is a subclass of UIScrollView), and use the -scrollViewDidScroll: delegate method to compare the table's content height and it's actual scroll position.

EDIT (something like this):

- (void)scrollViewDidScroll:(UIScrollView *)scrollView_ 
{   
    CGFloat actualPosition = scrollView_.contentOffset.y;
    CGFloat contentHeight = scrollView_.contentSize.height - (someArbitraryNumber);
    if (actualPosition >= contentHeight) {
        [self.newsFeedData_ addObjectsFromArray:self.newsFeedData_];
        [self.tableView reloadData];
     }
}

Problem

How do I do an infinite scrolling in a `UITableView`? I know how to do it using a `UIScrollView`, in which apple has demonstrated in one of the WWDC's video. I tried doing the following in `tableView:cellForRowAtIndexPath:`: ``` if (indexPath.row == [self.newsFeedData_ count] - 1) { [self.newsFeedData_ addObjectsFromArray:self.newsFeedData_]; [self.tableView reloadData]; } ``` but this fails. Any other idea?

Original source

Related problems