UITableView reloadData 什么时候会更新visibleCells?
我有一个 UITableView 实例 tableView
,它显示来自服务器的数据。
tableView
必须等待接收到数据,然后调用它的 reloadData
方法。一切都很好,效果很好。
现在我有一个特定的方法,我想在 tableView 完成创建第一组 visibleCells
后立即执行该方法。对于此示例,我将调用方法performFancyActionOnVisibleCells
。然而,似乎 reloadData 操作是异步的,所以我不能这样做,
[tableView reloadData];
[self performFancyActionOnVisibleCells];
因为执行第二行时,visibleCells 仍然是空的,所以我必须在调用它之前稍等一下。这让我想到了我的问题。
据我所知,没有像 tableView:didFinishReloadingData 这样的委托方法。但是,如果我想调用 performFancyActionOnVisibleCells
并确定 reloadData
已完成更新 visibleCells
属性,那会在哪里呢?
干杯,
EP。
I have a UITableView instance tableView
that displays data from a server.
The tableView
will have to wait until the data is received, and then gets a call to it's reloadData
method. All fine, works great.
Now I have a particular method that I want to perform right after the tableView finishes creating the first set of visibleCells
. For this example I'll call the method performFancyActionOnVisibleCells
. It seems however, that the reloadData action is asynchronous, so I can't just do
[tableView reloadData];
[self performFancyActionOnVisibleCells];
Because the visibleCells are still empty when that second line is executed, I will have to wait a bit before calling it. Which brings me to my question.
To my knowledge there is no delegate method like tableView:didFinishReloadingData
. But if I'd want to call performFancyActionOnVisibleCells
with the certainty that reloadData
has finished updating the visibleCells
property, where would that be?
Cheers,
EP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了直接回答您的问题,我不知道您正在寻找什么委托回调。
但是,
reloadData
将对每个可见行调用[tableView cellForRowAtIndexPath]
,因此您可以在该方法的底部进行调用。我认为
[tableView cellForRowAtIndexPath]
不会为表中的每个单元格调用,但会在单元格可见之前(例如,滚动时)根据需要由 UIKit 调用。To answer your question directly, I am not aware of any delegate callback for what you're looking for.
But,
reloadData
will call[tableView cellForRowAtIndexPath]
on each of your visable rows so you could put a call at the bottom of that method.I don't think that
[tableView cellForRowAtIndexPath]
gets called for every cell in your table but will get called by UIKit as required before the cell is made visable (for example, when scrolling).达米安听起来是对的,但我认为你应该看看你的策略......用户可能不会期望弹出一些东西(在随机时间)。我认为你应该先显示单元格,然后填充它们。使用进度指示器,直到数据到达。然后,当数据到达时,将其绘制到单元格中,然后您可以运行 fancyActionMethod。我希望这有帮助!
Damien sounds right but I think that you should look at your strategy...Users may not be expecting something to popup (at a random time). I think you should display the cells first and then populate them. Use a progress indicator until the data has arrived. Then when the data arrives, draw it into the cell and thereafter you can run your fancyActionMethod. I hope this helps!