11

When I upgrade to iOS 11, the tableview of my app suddenly cannot scroll smoothly. Whenever I scroll (or reloadData), the tableview will suddenly jump to a random content offset position.

I use mopub's placer to insert ads into tableview and I notice whenever the app performs [tableview reloadData], the tableview scroll offset will go wrong and jump to a random position.

Sean Cheng
  • 936
  • 7
  • 11
  • There seems to be a **bug** for when you use `UITableViewAutomaticDimension `. See [this answer](https://stackoverflow.com/questions/8640409/how-to-keep-uitableview-contentoffset-after-calling-reloaddata/31324129#31324129) and other answers to the question. – mfaani Oct 10 '18 at 03:57

1 Answers1

44

After one month after upgrade to iOS 11, I find this discussion: UITableView reload methods show behavior regression in Apple Developer Forums.

It turns out that this weird behavior is caused by [tableview reloadData], and mopub ad placer always calls [tableview reloadData]. Therefore the tableview with mopub ad placer will suffer this problem most.

To solve the problem, just set:

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

and all scroll and reloadData behavior will be really smooth like iOS 10.

Sean Cheng
  • 936
  • 7
  • 11
  • This solution worked for me as well. For `tableView.reloadData()` and `tableView.beginUpdates()/endUpdates()`. – Daniel Jan 05 '18 at 18:05
  • 1
    It's not for no reason this property is called `estimatedRowHeight` You need to give an estimation closest to the cell height. In my case 0 was completely wrong because my cell's height was rather big and the glitch persisted, so I set it to 100 and the problem was solved. I think the above answer `tableView.estimatedRowHeight = 0` works because the cell's height happens to be small. – Au Ris May 01 '18 at 08:35
  • @AuRis quoth the docs: "Set the value to 0 to disable estimated heights." – nolanw May 03 '18 at 20:48
  • @AuRis This was not my experience; the cell heights in my table fall pretty consistently somewhere between 120 and 250. Yet setting estimated row heights to anything in that range, if anything, only made the scrolling even more erratic. `0` is the only value at which the confusing jumps stopped. – Daniel Saner May 22 '18 at 10:07
  • 3
    What if my cell sizes are dynamic and I want to keep automatic cell height? – yigitserin Jun 12 '18 at 11:09
  • 1
    @user3179249, inspect this question and accepted answer https://stackoverflow.com/questions/28244475/reloaddata-of-uitableview-with-dynamic-cell-heights-causes-jumpy-scrolling – Hot'n'Young Jul 09 '18 at 08:49
  • Better answer in whole internet. – Alex Motor Jan 11 '19 at 13:41
  • 1
    The above answer works well. Thanks for saving my time. – Dnyaneshwar Wakchaure Oct 15 '19 at 11:20
  • 1
    Setting those three to zero solved the problem for me, and I was only using headers and footers of my own (no mopub ad placer). Although, my headers and footers varied by section, they were always the same for the view. Nevertheless, when changing the number of rows in a middle section (due to a button in that section), scrolling up caused jumps. So, plus 1. – Jeff May 04 '20 at 03:17