Skip to content

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

Open

Description

@rainypixels

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.

Activity

  1. rainypixels commented on Jul 31, 2015

    @rainypixels
    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.

  2. budidino commented on Nov 2, 2016

    @budidino

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

    Hope it helps someone

  3. yarodevuci commented on Nov 7, 2018

    @yarodevuci

    @budidino when do you call it?

  4. tickendy commented on Nov 19, 2018

    @tickendy

    @budidino when do you call it?

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

  5. dashared commented on Jan 29, 2019

    @dashared

    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.

  6. appleios commented on Dec 11, 2019

    @appleios

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions