UITableView with dynamic cell heights jumping when scrolling up after reloading cell

后端 未结 5 1419
孤街浪徒
孤街浪徒 2021-02-05 13:21

I have a table view with the potential for each cell to have its own height, thus isn\'t suitable to use rowHeight. Instead, right now I\'m using let indexSet

5条回答
  •  日久生厌
    2021-02-05 13:55

    This behavior appears to be a bug, if for no other reason than it's no longer reproducible on iOS 9. I'm sure that's not much consolation.

    The issue primarily derives from having an inaccurate estimate, like @NickCatib said. The best you can do on iOS 8 is to improve the estimation. A technique many have recommended is to cache heights in willDisplayCell and use them on subsequent calls to estimatedRowHeightAtIndexPath.

    You might be able to mitigate the behavior by not doing anything to get UITableView to discard its caches, like by modifying the content in a cell directly using cellForRowAtIndexPath rather than using reloading if it's onscreen. However, that won't help if you actually need to change the height of the cell.

    I'm afraid to say the bug can't be easily be fixed within a table view, as you don't have control over the layout. The bug can be more easily worked around in a subclass UICollectionViewFlowLayout by changing the contentOffsetAdjustment during invalidation, although that might not be terribly easy.

提交回复
热议问题