In my iOS 7 app, I have my view set to "extend edges under top bars" so my uitableview has the translucent effect when you scroll it under the navigation bar as you are scrolling down. But when you scroll back to the top, or when it loads, it properly positions the first cell below the nav bar, not underneath it.
The problem is, that indexPathsForVisibleRows sees the cell underneath the nav bar. So for example, if we scroll down so that all we see is cell index 1 (the 2nd cell), cell index 0 is underneath the nav bar and when we call indexPathsForVisibleRows, it returns index 0 instead of index 1 as the lowest cell that is visible.
Any other way around this?
One option is to get the y-coordinate of the bottom of the navbar and translate this to the coordinate system of the tableview. Once you have that, you can get the indexPath or cell from the tableview based on that point.
UINavigationBar *navbar = self.navigationController.navigationBar;
CGRect localFrame = [self.tableView convertRect:navbar.bounds fromView:navbar];
CGPoint point = CGPointMake(0, localFrame.origin.y + localFrame.size.height + 1);
NSIndexPath *path = [self.tableView indexPathForRowAtPoint:point];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With