Detect the current top cell in a UITableView after scrolling

You could try using UITableView‘s -indexPathsForVisibleRows or -indexPathForRowAtPoint.

For example, let’s say that you want to print the indexPath of the topmost visible cell, when you stop dragging your table. You could do something like this:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    NSIndexPath *firstVisibleIndexPath = [[self.tableView indexPathsForVisibleRows] objectAtIndex:0];
    NSLog(@"first visible cell's section: %i, row: %i", firstVisibleIndexPath.section, firstVisibleIndexPath.row);
}

For Swift 3.0

let topVisibleIndexPath:IndexPath = self.tableView.indexPathsForVisibleRows![0]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)