2011-09-20 138 views
3

即时通讯实现一个应用程序,显示一些Twitter数据,当工作在WiFi是好的,但在3g崩溃,我得出的结论是,因为NSURLRequest获取数据填充该表需要更长的时间才能加载,因此当表甚至没有加载密钥时,表最终会调用对象的密钥,所以问题是,我怎么知道NSURLRequest何时完成加载? [我检查了类参考,但没有看到它?]如何知道什么时候NSURLRequest完成加载

非常感谢!

回答

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 { 
相关问题