3

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

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

非常感谢!

4

1 回答 1

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 {
于 2011-09-20T14:12:30.103 回答