Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new cell while scrolling causes table view to jump #26

Open
rainypixels opened this issue Jul 31, 2015 · 6 comments
Open

Adding new cell while scrolling causes table view to jump #26

rainypixels opened this issue Jul 31, 2015 · 6 comments

Comments

@rainypixels
Copy link

If you...

  1. Swipe the tableview to scroll it fast (or slow).
  2. Hit the '+' button while it's scrolling

... the tableview jumps up before it continues scrolling from a random location. This doesn't happen if the tableview is not scrolling (i.e. it's stationary) when you add cells. I'm assuming this is another UITableView auto-sizing bug that has something to do with scrollView frame and offset calculations when the table view is being scrolled.

Anyone have any ideas for a workaround? I wanted to check before I try to get too clever.

@rainypixels
Copy link
Author

Turns out that if you change the addRow method to use reloadData as follows, the jumping issue disappears.

func addRow()
{
    model.addSingleItem()
    self.tableView.reloadData()
}

It certainly seems like insertRowsAtIndexPath:withRowAnimation: is the problem here because it probably attempts to adjust scrollview height immediately but by using the estimatedRowHeight of the newly inserted rows.

Calling reloadData whenever a couple of cells are added certainly seems like a less than ideal workaround, so I'm still interested to see if anyone has better ideas.

@budidino
Copy link

budidino commented Nov 2, 2016

This stops the tableView from scrolling and therefore prevents the glitch:
tableView.setContentOffset(tableView.contentOffset, animated: false)

Hope it helps someone

@yarodevuci
Copy link

@budidino when do you call it?

@tickendy
Copy link

@budidino when do you call it?

call "tableView.setContentOffset(tableView.contentOffset, animated: false)" just before you reloadData()

@dashared
Copy link

https://brigade.engineering/reloading-uitableview-while-animating-scroll-in-ios-11-f89910c958b6 hope this will help somebody! I personally found it very useful while I stuck with the problem how to delete rows while scrolling.

@appleios
Copy link

This actually helped me (see https://forums.developer.apple.com/thread/86703)

    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants