2

Can anyone help me understand or solve this UITableView glitch in iOS11. I have managed to reproduce my issue in a fairly simple test case.

https://github.com/trapper-/iOS11-tableview-glitch

When reloading cells near the bottom of a tableview the reloaded cell will start to scroll weirdly and other cells start to move and hop around.

It gets much worse when reloading multiple cells, but I didn't want to complicate this simple example.

  • Edit: This issue only occurs in iOS11, works fine in iOS10 & iOS12. So you need to download the iOS11 simulator to test this in Xcode 10
trapper
  • 11,716
  • 7
  • 38
  • 82

4 Answers4

8

This should help:

[UIView performWithoutAnimation:^{
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
Bessi
  • 161
  • 1
  • 4
  • Unfortunately I do still get the glitch here - it does happen very quickly so hard to notice. Quite a compromise removing the animated reload though. – trapper Sep 19 '18 at 02:16
4

If I use like this, its working.

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
Vini App
  • 7,339
  • 2
  • 26
  • 43
  • Interesting that does seem to help, as long as the cells don't exceed 100 height, if so then the glitch is back. Change to `stringByPaddingToLength:100` and you will see the issue comes back. – trapper Oct 11 '17 at 04:33
  • In iOS 11, the default table row height is “automatic” so you need to implement estimatedHeightForRow or heightForRow and you must return a reasonable value or you need to explicitly set the tableviews row height property to disable the automatic row height – Paulw11 Oct 11 '17 at 07:39
  • So I have completely dynamic content, could be anything from 1 line to 20, what is a reasonable value then? – trapper Oct 11 '17 at 08:19
  • You should calculate the actual value if possible. If you don’t yet know then return a default value and once you know the actual height for the cell (say in cellForRow) you can store that height in an array for the row and return that value next time the estimated height and height for methods are called – Paulw11 Oct 11 '17 at 08:41
3

Try providing estimatedRowHeight to 0 to table view on viewDidLoad. It works for me.

torap
  • 656
  • 6
  • 15
0

Please try setting you're table view estimatedRowHeight (in the viewDidLoad method): self.tableView.estimatedRowHeight = 100;

The tableView.rowHeight is set to UITableViewAutomaticDimension by default but you need to set the estimatedRowHeight From apple - "To enable self-sizing table view cells, you must set the table view’s rowHeight property to UITableViewAutomaticDimension. You must also assign a value to the estimatedRowHeight property. As soon as both of these properties are set, the system uses Auto Layout to calculate the row’s actual height."

You can check out: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html

Boaz Frenkel
  • 618
  • 5
  • 15
  • That just disables self-sizing table cells. All the cells become one line. – trapper Feb 06 '18 at 08:43
  • @trapper I added self.tableView.estimatedRowHeight = 100; to your project viewController's viewDidLoad and it seems to solve your issue. Your tableView.rowHeight is set to UITableViewAutomaticDimension by default but you need to set the estimatedRowHeight from apple: "To enable self-sizing table view cells, you must set the table view’s rowHeight property to UITableViewAutomaticDimension. You must also assign a value to the estimatedRowHeight property. As soon as both of these properties are set, the system uses Auto Layout to calculate the row’s actual height." – Boaz Frenkel Feb 07 '18 at 11:30
  • 1
    After my comment you edited your answer and completely changed it. lol – trapper Feb 21 '18 at 06:37
  • @trapper yes :) sorry for that.. but did this new answer work for you? – Boaz Frenkel Feb 21 '18 at 15:14
  • @trapper did it? ;) – Boaz Frenkel Sep 18 '18 at 13:47
  • Vini App has a similar answer. This works only as long as the cells don't exceed 100 height, if so then the glitch is back. Change to stringByPaddingToLength:100 and you will see the issue comes back. Also this issue only occurs in iOS11, works fine in iOS10 & iOS12 so you need to download the iOS11 simulator to test in Xcode 10. – trapper Sep 19 '18 at 02:09
  • @trapper Thanks – Boaz Frenkel Sep 19 '18 at 08:12