仅在reloadData完成后调用函数 [英] Call function only after reloadData has finished
问题描述
我有一个 tableView
,并且需要在重新加载 tableView
后执行一个函数。我怎么知道 reloadData
是否已经完成?假设我有methodA填充 tableView
,一旦 [tableView1 reloadData]
已经完成,我想打电话的methodB。谁能帮我这个?我一直在搜索......谢谢!
I have a tableView
and need to perform a function once the tableView
has been reloaded. How do I know if reloadData
has finished? Lets say I have methodA that populates the tableView
, and once [tableView1 reloadData]
has been completed, I want to call methodB. Can anyone help me with this? I've been searching for hours... Thank you!
- (void) methodA
{
NSString *URLa = [NSString stringWithFormat:@"http://www.website.com/page.php?
v1=%@&v2=%@&v3=%@",v1, v2, v3];
NSURL *url = [NSURL URLa];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
(void) [[NSURLConnection alloc] initWithRequest:request delegate:self];
[tableView1 reloadData];
}
推荐答案
问题是你在启动URL请求后立即调用 reloadData
。这没有意义,因为此时请求尚未完成。
The problem is that you call reloadData
immediately after starting the URL request. That does not make sense because the request has not been completed at that point.
正确的方法是调用 reloadData
和 methodB
在 connectionDidFinishLoading
中,在您使用URL请求的响应更新数据源之后。此时,您知道行数是否为零,并且无需等待以使表视图更新完成。
The correct way would be to call reloadData
and methodB
in connectionDidFinishLoading
, after you have updated your data source with the response from the URL request. At that point you know if the number of rows is zero or not, and there is no need to wait for the table view update to complete.
这篇关于仅在reloadData完成后调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!