tableView.setContentOffset(_, animated:) do not work after beginUpdates()

二次信任 提交于 2021-02-10 18:28:41

问题


After using

beginUpdates()
endUpdates()

This method ->

tableView.setContentOffset(_, animated:) // do not work

Do not work after calling that 2 methods (even if I use timer), but works without them! Any ideas why?

setContentOffset works only if I swipe tableView manually after beginUpdates() + endUpdates() and BEFORE setContentOffset is being called.

scrollToRowAtIndexPath works fine though but I need only setContentOffset.


回答1:


tableView.setContentOffset(_, animated:) works now when I calling with a dispatch to the main thread! So,

beginUpdates()
endUpdates()

DispatchQueue.main.async {
    tableView.setContentOffset(CGPoint(x: 0, y: -offset), animated: true)
}

This way works.



来源:https://stackoverflow.com/questions/59631998/tableview-setcontentoffset-animated-do-not-work-after-beginupdates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!