Reputation: 3247
I want to be able to scroll to a header and not the first item under that header. The reason this is important is that the atScrollPosition parameter is set to Top, and I scroll to the zeroth item in a particular section. This then hides the header and the user doesn't receive feedback validating that they have been scrolled to the right section.
Does anyone know how to do this?
Upvotes: 1
Views: 1056
Reputation: 1028
Instead of scrollToRowAtIndexPath
, use scrollRectToVisible
. You can get precise positioning by passing in a rect with a size that is the same as the table view.
So if you want your header to be positioned exactly at the top, use the header's frame, setting the height to that of the table view, and then pass that to scrollRectToVisible
.
Something like:
CGRect sectionRect = [tableView rectForSection:indexOfSectionToScrollTo];
[tableView scrollRectToVisible:sectionRect animated:YES];
See this
Upvotes: 4