我实现了一个显示一些 Twitter 数据的应用程序,在 wifi 上工作时没问题,但在 3g 崩溃时,我得出的结论是因为获取填充表的数据的 NSURLRequest 需要更长的时间来加载所以当键甚至还没有加载时,表最终调用一个对象作为键,
所以问题是, - 我怎么知道 NSURLRequest 何时完成加载? [我查看了 Class Reference 但没有看到它??]
非常感谢!
最佳答案
委托(delegate)方法在请求对应的 NSURLConnection 上被调用,例如
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
然后您将收到各种回调,包括完成的回调,如下所示:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{}
其他委托(delegate)回调是:
- (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 {
关于ios - 如何知道 NSURLRequest 何时完成加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7486491/