iOS:如何知道 reloadData() 已完成其任务? [英] iOS: How to know reloadData() was completed its task?

查看:28
本文介绍了iOS:如何知道 reloadData() 已完成其任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想滚动到给定的索引 (self.boldRowPath),但是当我调试时 scrollToRowreloadData() 之前执行.

I want to scroll to a given index (self.boldRowPath), but when I debug scrollToRow is performed before reloadData().

如何知道reloadData已经完成?

func getAllTimeEvent()  {
    self.arrAllTimeEvent = ModelManager.getInstance().getAllTimeEvent(from: self.apportmentDateFrom, to: self.apportmentDateTo)
    self.tblTimeEvent.reloadData()
    self.tblTimeEvent.scrollToRow(at: self.boldRowPath ?? [0,0], at: .top, animated: true)
 }

任何帮助将不胜感激.

推荐答案

尝试这样做,应该可以:

Try doing this, it should work:

self.tblTimeEvent.reloadData()
DispatchQueue.main.async(execute: {
    self.tblTimeEvent.scrollToRow(at: self.boldRowPath ?? [0,0], at: .top, animated: true)
})

这将在主线程上执行 scrollToRow,这意味着在 reloadData 完成后(因为它在主线程上)

This will execute the scrollToRow on the main thread, that means after the reloadData is done (because it is on the main thread)

这篇关于iOS:如何知道 reloadData() 已完成其任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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