views:

499

answers:

1

Is there any way to find out which UITableViewCell is at the top of the scroll window?

I'd like to get the current scroll position so that I can save it when the app exits. When the app gets started I want to scroll to the position it was at when it last exited.

+3  A: 

You can easily grab the exact offset of the table view by looking at its contentOffset property. For the vertical scroll, look at:

tableView.contentOffset.y;
Ben Gottlieb
+1 Was going to answer the same.
Jacob Relkin
That's a CGPoint in the scroll view, I'm not sure how I can tell which UITableViewCell that corresponds to.
progrmr
You don't need the cell if you use the offset; just set the offset when you re-enter the view. However, if you MUST know the cell at the top, just use: [tableView indexPathForRowAtPoint: CGPointMake(0, 0)];
Ben Gottlieb
using contentOffset works perfectly, it returns the scroll position exactly where it was when the app last quit. Thanks! I didn't need to know which cell it was after all.
progrmr