UITableView Scrolls to Top on Cell Refresh

后端 未结 4 1841
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 10:08

I have a UITableView with a cell that is dynamically sized to fit a UITextView inside it. Whenever a key is typed, the cell checks to see if the calculated height has increased,

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 10:21

    Here is my UITableView extension that works perfectly. In Swift 2.1. Based on the accepted answer.

    extension UITableView
    {
        func reloadDataAnimatedKeepingOffset()
        {
            let offset = contentOffset
            UIView.setAnimationsEnabled(false)
            beginUpdates()
            endUpdates()
            UIView.setAnimationsEnabled(true)
            layoutIfNeeded()
            contentOffset = offset
        }
    }
    

提交回复
热议问题