iphone - NSURL 的结果不一致

标签 iphone objective-c ios nsurl

使用以下代码发出我的请求,我注意到数据有时不会加载或完全加载,这总是在应用程序首次启动时发生。有什么想法吗?我尝试在connectionDidFinishLoading中放入[tableView刷新],但这似乎没有帮助,有什么想法吗?感谢您的浏览

.h:
    NSMutableData *responseData;

.m:
    - (void)load {
        NSURL *myURL = [NSURL URLWithString:@""];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
                                                 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                             timeoutInterval:60];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [responseData release];
    [connection release];
    [textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSLog(@"Succeeded! Received %d bytes of data",[responseData
                                                   length]);
    NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];

}

最佳答案

您确定您的数据没有加载吗?尝试使用 [tableView reloadData]; 而不是 refresh

关于iphone - NSURL 的结果不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6975749/

相关文章:

php - 如何通过 AFNetworking API 调用使用 gzip 解压缩?

iphone - 调用mapViewDidFailLoadingMap委托(delegate)方法时出现错误== 0

ios - viewDidLoad 和 ViewDidAppear 未被调用

ios - 核心数据 - 检查是否为 null - iOS

objective-c - 检索城市信息(酒店、餐厅、景点等)

objective-c - 当用户单击时如何禁用 UIButton 的突出显示

ios - 使用 PhoneGap(构建与 xCode)我的 iOS 应用程序可以有多大?

ios - 使用 Storyboard的 ios View Controller 的通用基类

ios - 在这种情况下,mapView :viewForAnnotation: will be called?

iphone - 将 NSMutableArray 保存到 plist 中?