【发布时间】:2014-02-19 15:00:48
【问题描述】:
我有一个从网络服务器获得的 NSData 对象。
这个数据对象的内容应该是一个 UIImage 。但是当我在以下代码中使用它时:-
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData * responseData, NSError *err) {
if (err) {
NSLog(@"Err %@",err.description);
}else
{
if (responseData)
{
NSLog(@"Data Length %d ",[responseData length]);
UIImage *img = [[UIImage alloc] initWithData:responseData];
if (img) {
NSLog(@"image in not null");
self.imageView.image = img;
}
else
{
NSLog(@"image is null");
}
}
else
{
NSLog(@"not returning anything");
}
}
}];
输出说:-
Data Length 2786779
image is null
所以我猜它不是图像
有没有办法让我知道这个 NSData 包含哪个类实例
PS:- 我也用过
NSLog("Description %@",data.description);
但它只生成了大量的十六进制代码
【问题讨论】:
-
isKindofClass 你试过了吗?
-
来自远程服务器的图像数据可能是Base64编码的,你可以解码。
-
来自文档:“指定数据的新图像对象,如果方法无法从指定数据初始化图像,则为 nil。”您的数据未被识别为图像,可能是后端问题?
-
您确定您的网址是图片网址吗?您可以尝试下载类似 google 图像的简单图像并验证:google.fr/images/srpr/logo11w.png。
-
@OMerObaid :嗯......那不是要返回我 NSData 吗?因为它是一个 NSData 对象
标签: ios iphone objective-c cocoa-touch nsdata