Ios NSURL中的UIImageView为空
我没有收到任何错误,试图显示从一个URL的图像,但没有显示任何东西。在尝试显示图像之前,是否必须在本地下载图像?请原谅我的无知,我是一个完全的iOS开发新手哈哈Ios NSURL中的UIImageView为空,ios,objective-c,uiimageview,uiimage,uikit,Ios,Objective C,Uiimageview,Uiimage,Uikit,我没有收到任何错误,试图显示从一个URL的图像,但没有显示任何东西。在尝试显示图像之前,是否必须在本地下载图像?请原谅我的无知,我是一个完全的iOS开发新手哈哈 - (void) viewDidLoad { NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads
- (void) viewDidLoad {
NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads/2017/08/Screen-Shot-2017-08-22-at-7.24.16-AM-e1503412089169.png"]];
UIImage * imgBuffer = [[UIImage alloc] initWithData:dataBuff];
img = [[UIImageView alloc] initWithImage:imgBuffer];
img.image = randImgBuffer;
}
}
(
img
在我的头文件中定义为UIImageView
)代码中的问题尝试此解决方案
- (void) viewDidLoad {
NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads/2017/08/Screen-Shot-2017-08-22-at-7.24.16-AM-e1503412089169.png"]];
UIImage * imgBuffer = [[UIImage alloc] initWithData:dataBuff];
img.image = imgBuffer;
}
}
完美的非常感谢:)