Error: UITableView jump to top with UITableViewAutomaticDimension

前端 未结 7 1694
半阙折子戏
半阙折子戏 2020-12-05 15:17

I am using UITableView with estimatedRowHeight and UITableViewAutomaticDimension. Also I am using NSFetchedResultsControllerDele

相关标签:
7条回答
  • 2020-12-05 15:46

    This is default behaviour of tableview, inserting an row in tableview scroll it to top. I did faced the same issue with my app. Here is how i able to manage the content offset of tableview, follow the steps,

    1)Store the content offset of UITableview before inserting row or section.

    2)Insert objects in array.

    3)Reload the tableview

    4)Subtract the difference and set the content offset manually.

    let oldOffset: CGFloat = tblTest.contentSize.height
    tblTest.reloadData()
    let newOffset: CGFloat = tblTest.contentSize.height
    tblTest.setContentOffset(CGPointMake(0, (newOffset - oldOffset)), animated: false)
    

    This is how i have done in my applications so far, and with dynamic cell to overcome the reinitialise cell everytime, it is working just awesome.

    0 讨论(0)
提交回复
热议问题