gpt4 book ai didi

ios - iphone 图片下载后不出现

转载 作者:行者123 更新时间:2023-11-28 20:01:24 24 4
gpt4 key购买 nike

我正在构建一个简单的应用程序来显示图像。

我发了图片url,应该可以下载

这是我的代码:

#import "ImageViewController.h"

@interface ImageViewController ()
@property (nonatomic, strong) UIImageView * imageView;
@property (nonatomic, strong) UIImage * image;
@end

@implementation ImageViewController

-(void)setImageURL:(NSURL *)imageURL{
_imageURL = imageURL;
self.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
}

-(UIImageView*)imageView{
if(!_imageView)
return [[UIImageView alloc]init];
return _imageView;
}


-(UIImage*)image{
return self.imageView.image;
}

-(void)setImage:(UIImage *)image{
self.imageView.image = image;
[self.imageView sizeToFit];
}

-(void)viewDidLoad{
[self.view addSubview:self.imageView];
NSLog(@"Image Url = %@", self.imageURL);
}

@end

我这样调用它:

if ([segue.destinationViewController isKindOfClass:[ImageViewController class]]){
ImageViewController* ivc = (ImageViewController*)segue.destinationViewController;
ivc.imageURL = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"http://images.apple.com/v/iphone-5s/gallery/a/images/download/%@.jpg", segue.identifier]];

我 100% 确定传递的 url 是正确的,因为我已经通过调试检查过了

该图片确实正在下载,因为它的尺寸很大,并且在下载时屏幕被遮挡。

问题是 imageView 在完成下载后不显示它。

你能帮帮我吗?

编辑

头文件

#import <UIKit/UIKit.h>

@interface ImageViewController : UIViewController
@property(nonatomic, strong) NSURL* imageURL;
@end

这是我所有的代码,所以如果你想测试它。

编辑2

我有一个 ScrollView ,也许这就是问题所在?请检查图像

enter image description here

最佳答案

imageView 属性的 getter 有问题。您不是在初始化属性,而是每次都返回一个不同的对象。替换行:

return [[UIImageView alloc]init]; 

_imageView = [[UIImageView alloc]init];

关于ios - iphone 图片下载后不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23884751/

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