gpt4 book ai didi

ios - 从 URL 获取图像后 ImageView 未更新

转载 作者:行者123 更新时间:2023-11-29 04:11:12 25 4
gpt4 key购买 nike

我正在使用 AFNetworking 类别 UIImageView+AFNetworking.h 来从 S3 下载图像。我收到一个预签名的 URLRequest 并继续获取图像。这是在仅用于显示照片的 Controller 中:

- (void)viewWillAppear:(BOOL)animated
{
NSURLRequest *request = [BFAWSUploader downloadPhotoWithFileName:[NSString stringWithFormat:@"%@.jpg", _topicMessage.attachment_s3_name]];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[_imageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"Default.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"Pulled down image successfully");
[hud hide:YES];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Failed to pull down image");
}];
}

我看到日志条目“已成功下拉图像”,但此后我没有看到 ImageView 更新。相反,我必须离开 View Controller 然后返回,我将看到缓存的条目。

最佳答案

来自 UIImageView+AFNetworking.h :

“如果指定了成功 block ,则该 block 负责在返回之前设置 ImageView 的图像。如果未指定成功 block ,则执行使用 self.image = image 设置图像的默认行为。 ”

所以,你需要_imageView.image = image在你的成功 block 内。

关于ios - 从 URL 获取图像后 ImageView 未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14382755/

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