如何知道 NSURLRequest 何时完成加载

编程入门 行业动态 更新时间:2024-10-11 01:14:04
本文介绍了如何知道 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 何时完成加载

本文发布于:2023-11-25 11:02:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629492.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   NSURLRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!