Reputation: 117
I try to build a talbleview where a every row can display a sublist when it is tapped. In order to that I update the Datamodel and call
[self.tableView insertRowsAtIndexPaths:addedIndexPaths withRowAnimation:(UITableViewRowAnimationTop)];
The animation takes place while the rows are visible. The added cells display correctly after the animation, but while the animating the tableview sometimes scrolls up. This happens especially in the last section of the tableview. Also the tableview always scrolls up when table until the top of the cell that is above the inserted cells is visible.
I want to fix the contentoffset during the visible animation.
I tried to set the context offset inside of begin updates
and end updates
, but this did not work because the animation would scroll up and you would see the content scrolling back into position.
I use auto layout to make the cells self-sizing.
How can I keep the content offset of the tableview constant while inserting visible cells?
Upvotes: 4
Views: 508
Reputation: 10317
I figured out the issue. The self-resizing is the root cause.
Don't use self-resizing Just remove these lines:
tableView.estimatedRowHeight = 123
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
Upvotes: 0