如何知道NSURLRequest何时完成加载

时间:2011-09-20 14:06:09

标签: ios uitableview nsurlrequest activity-finish

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

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

非常感谢!

1 个答案:

答案 0 :(得分:9)

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

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

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

- (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 {