gpt4 book ai didi

ios - 显示 AFNetworking+UIImageView 占位符图像,但不显示 URL 图像

转载 作者:可可西里 更新时间:2023-11-01 03:28:13 26 4
gpt4 key购买 nike

我正在尝试使用 AFNetworking UIImageView 调用从 URL 加载图像,如下所示:

[self.image setImageWithURL:[NSURL URLWithString:feed.imageURL] placeholderImage:     [UIImage imageNamed:@"logo"]];

占位符图像始终显示,但“feed.imageURL”中的实际图像永远不会显示。我已经验证该 URL 实际上是正确的。我什至对其进行了硬编码以确保,但仍然一无所获。

我的基本应用程序设置是一个选项卡 Controller ...在 viewDidLoad 中,我调用了一个方法“fetchFeed”,该方法执行 HTTP 请求以收集我的 JSON 数据。

我的请求 block 看起来像:

AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self parseDictionary:JSON];
isLoading = NO;
[self.tableView reloadData];

} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Error: %@", error);
[self showNetworkError];
isLoading = NO;
[self.tableView reloadData];
}];
operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
[queue addOperation:operation];

最佳答案

原来我请求图像的服务器正在发送 content-type "image/jpg" 并且默认情况下 AFNetworking 不支持这种文件类型。

我将 AFImageRequestOperation 中的类方法更改为如下所示:

+ (NSSet *)defaultAcceptableContentTypes {
return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon" @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", @"image/jpg", nil];
}

它解决了我的问题。

关于ios - 显示 AFNetworking+UIImageView 占位符图像,但不显示 URL 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9459703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com