tableView.setContentOffset(_, animation:) 在 beginUpdates() 后不起作用 [英] tableView.setContentOffset(_, animated:) do not work after beginUpdates()

查看:65
本文介绍了tableView.setContentOffset(_, animation:) 在 beginUpdates() 后不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用后

beginUpdates()
endUpdates()

这个方法->

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

调用这 2 个方法后不起作用(即使我使用计时器),但没有它们也可以工作!任何想法为什么?

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

setContentOffset 仅在我在 beginUpdates() + endUpdates() 之后手动滑动 tableView 并且在 setContentOffset 被调用之前才起作用.

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

scrollToRowAtIndexPath 虽然工作正常,但我只需要 setContentOffset.

scrollToRowAtIndexPath works fine though but I need only setContentOffset.

推荐答案

tableView.setContentOffset(_, animation:) 现在可以在我调用主线程时使用!所以,

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)
}

这种方式有效.

这篇关于tableView.setContentOffset(_, animation:) 在 beginUpdates() 后不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆