我想从 URL 中获取图像并将其放入 NSArray,但在以下代码中不起作用,请帮助:
@interface DataViewController ()
@property (readonly, strong, nonatomic) NSArray *picData;
@end
@implementation DataViewController
- (void)viewDidLoad {
NSString *imageUrlStringAA=@"http://aaa.net/AA.png";
NSString *imageUrlStringBB=@"http://aaa.net/BB.png";
NSURL *urlAA=[NSURL URLWithString:imageUrlStringAA];
NSURL *urlBB=[NSURL URLWithString:imageUrlStringBB];
NSData *dataAA=[[NSData alloc] initWithContentsOfURL:urlAA];
NSData *dataBB=[[NSData alloc] initWithContentsOfURL:urlBB];
UIImage *imageAA=[UIImage imageWithData:dataAA];
UIImage *imageBB=[UIImage imageWithData:dataBB];
_picData = [NSArray arrayWithObjects:imageAA, imageBB, nil];
感谢您的任何想法。
首先从 http 协议(protocol)下载任何东西,然后在 info.plist 中添加以下字典
现在试试这段代码:
@interface DataViewController ()
@property (readonly, strong, nonatomic) NSArray *picData;
@end
@implementation DataViewController
- (void)viewDidLoad {
NSString *imageUrlStringAA=@"http://www.hdwallpapers.in/download/antelope_canyon-360x640.jpg";
NSString *imageUrlStringBB=@"http://www.hdwallpapers.in/download/vegeta_dragon_ball_super-360x640.jpg";
NSURL *urlAA=[NSURL URLWithString:imageUrlStringAA];
NSURL *urlBB=[NSURL URLWithString:imageUrlStringBB];
NSData *dataAA=[[NSData alloc] initWithContentsOfURL:urlAA];
NSData *dataBB=[[NSData alloc] initWithContentsOfURL:urlBB];
UIImage *imageAA=[UIImage imageWithData:dataAA];
UIImage *imageBB=[UIImage imageWithData:dataBB];
_picData = [NSArray arrayWithObjects:imageAA, imageBB, nil];
}
关于ios - 如何从 URL 获取图像并放入 NSArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43132267/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |