本文介绍了如何检查NSData是否对UIImage中的使用有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSError *error = nil;
NSURL *url = [NSURL URLWithString:[imageLinks objectAtIndex:0]];
NSData *tdata = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
if (error) {
NSLog(@"%@", [error localizedDescription]);
}else {
// no error, this one is being called within my app
NSLog(@"Data loaded successfully");
}
self.pictureView1.image = [UIImage imageWithData:tdata];
我有一个jpeg文件,我可以确认URL内容是成功收集的,但是当我尝试将我的图像数据放入 UIImage
我的应用程序失败。我想知道是否有任何NSData检查确认它可用于 UIImage
。
I have a jpeg file, I can confirm that the URL content is gathered successfully, but when I try to put my image data into the UIImage
my app fails. I wonder if there is any check for NSData to confirm it is usable for UIImage
.
我也不知道知道导致这种失败的原因,以及如何防止它。任何帮助将不胜感激。
I also don't know what causes this failure, and how to prevent it. Any help would be appreciated.
推荐答案
如上所述 imageWithData:如果UIImage无法从数据创建图像,则返回nil。在运行时处理此问题的正确方法是在该方法返回nil时提供占位符图像。
这篇关于如何检查NSData是否对UIImage中的使用有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!