简体   繁体   English

swift tableview.scrollToRow()冻结ui

[英]swift tableview.scrollToRow() freezes ui

I have a ViewController with a tableview inside. 我有一个ViewController里面有一个tableview

I add some rows and call tableview.reloadData() . 我添加一些行并调用tableview.reloadData()

I use the tableview.scrollToRow() call to scroll to bottom of tableview . 我使用tableview.scrollToRow()调用滚动到tableview底部。 and it takes quite long which freezes the UI. 而且需要很长时间才能冻结UI。

Is there a way to do this in another thread or something? 有没有办法在另一个线程中执行此操作? I even put it in DispatchQueue but still freezes the UI. 我什至把它放在DispatchQueue但仍然冻结UI。 It almost takes about 5 seconds to execute the scrollToRow() call. 执行scrollToRow()大约需要5秒钟。

 DispatchQueue.main.async {
  self.tableView.reloadData()
  let indexPath = IndexPath(row: count-1, section: 0)
  self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
 }

If anyone is interested I have found that this is not a problem on 11.4 iOS. 如果有人感兴趣,我发现这在11.4 iOS上不是问题。 Suggest update to latest IOS and try if you are having similar issue 建议更新到最新的IOS,如果遇到类似问题,请尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM