如何知道 NSURLRequest 何时完成加载 [英] how to know when NSURLRequest finish loading

查看:64
本文介绍了如何知道 NSURLRequest 何时完成加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个显示一些 Twitter 数据的应用程序,在 wifi 上工作时可以,但是在 3g 崩溃时,我得出的结论是,因为获取填充表的数据的 NSURLRequest 需要更长的时间来加载所以表最终调用一个对象作为键,当键甚至还没有加载时,

Im implementing an app that shows some Twitter data, when is working on wifi is ok, but on 3g crashes, I have come to the conclusion that is because the NSURLRequest that fetchs the data that populates the table takes longer to load so the table ends up calling an object for key, when the keys havent even loaded,

所以问题是,- 我怎么知道 NSURLRequest 何时完成加载?[我检查了类参考但没有看到它??]

So the question is, - how can I know when the NSURLRequest finished loading? [I checked the Class Reference but didnt see it??]

非常感谢!

推荐答案

委托方法在请求对应的 NSURLConnection 上调用,例如

The delegate methods are invoked on the request's corresponding NSURLConnection, e.g.

    urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

然后您将收到各种回调,包括完成的回调,如下所示:

You will then receive various callbacks included the finished callback as follows:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{}

其他委托回调是:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection{

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

这篇关于如何知道 NSURLRequest 何时完成加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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