Reputation: 67802
I have a tableview. On tap, a cell expands into a form, and I would like the cell to scroll up to start right below the navigation bar. How do I achieve this?
Here's the starting state:
Currently, after tap:
And here's what I want:
Upvotes: 1
Views: 190
Reputation: 119242
scrollToRowAtIndexPath...
or scrollToNearestSelectedRow...
both take "scroll position" arguments which allow the selection to go to the top, middle or bottom of the table view. That should give you what you want.
Upvotes: 1
Reputation: 9354
You need something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Perform cell change height code here
// ...
// After that scroll to this cell
CGFloat sectionHeaderHeight = [self tableView:tableView heightForHeaderInSection:indexPath.section];
CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath];
[tableView setContentOffset:CGPointMake(0, cellFrame.origin.y - sectionHeaderHeight) animated:YES];
}
Upvotes: 2