如何在加载数据之前停止加载UITableView? [英] How to stop UITableView from loading until data has been fetched?
问题描述
我理解 UITableView
将调用 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
获取表视图的每个单元格的方法。假设我的数据源是通过互联网获取的,我必须考虑延迟。 停止调用此方法的最佳方法是什么?它应该阻止应用程序中的布尔标志吗?我应该从我的应用程序中再次调用 cellForRowAtIndexPath
吗?
I understand that UITableView
will call -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method to get each of the cells for the table view. Say I have my data source is fetched over the internet and I have to account for latency. What will be the best way of "stopping" this method from being called? Should it block on a boolean flag in the application? Should I just call cellForRowAtIndexPath
again from within my application?
我不确定函数何时被调用,即 UITableView
刷新自身的频率。任何解释都会有所帮助!谢谢!
I am uncertain as to when the function gets called, ie, how often the UITableView
"refreshes" itself. Any explanations will be helpful! Thanks!
推荐答案
如果您没有数据,或者您没有其他单元格的数据,那么<$只要您没有告诉UTableView您有rowCounts或new rowCounts,就不会调用c $ c> cellForRowAtIndex:。该值设置在 numberOfRowsInSection:
。
If you don't have data, or you don't have the data for additional cells, then cellForRowAtIndex:
will not be called as long as you don't tell the UTableView that you have rowCounts or new rowCounts. That value is being set in numberOfRowsInSection:
.
换句话说,不报告 numberOfRowsInSection:
,直到你实际拥有该数据为止,然后 cellForRowAtIndexPath:
将不会过早被调用。
In other words, don't report any new cells in numberOfRowsInSection:
, until you actually have that data in hand, and then cellForRowAtIndexPath:
won't be called prematurely.
当你获得额外的行数据时,然后调用 reloadData
来让UITableView询问行数和然后调用 cellForRowAtIndex:
。
When you do get the additional row data, then call reloadData
to get the UITableView to ask for the number of rows and then call cellForRowAtIndex:
.
这篇关于如何在加载数据之前停止加载UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!