我刚遇到一个很奇怪的问题。 我目前正在开发一个应用程序,它以异步方式从远程主机加载图像,然后显示它们。
以下代码正在后台线程中执行,通过 performSelectorInBackground
调用
NSURL *url = [NSURL URLWithString:[ChannelThumbnailURI stringByReplacingOccurrencesOfString:@"{PersonName}" withString:person.Name]];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *thumb = [UIImage imageWithData:imageData];
现在有趣的是,我在不同的设备上得到了不同的结果(所有设备都使用相同的 iOS,4.3.3)
thumb 在我的旧 iPad 上是 nil 而在相同的上下文中它在我的 iPad2 上是一个有效的图像
我真的不知道这里可能有什么问题。 感谢您的输入。
山姆
最佳答案
我看不出为什么这会在 iPad2 上运行而不是在 iPad1 上运行的直接原因,请尝试添加更多调试代码以查看哪里出错了。
NSString* urlString = [ChannelThumbnailURI stringByReplacingOccurrencesOfString:@"{PersonName}" withString:person.Name];
if (urlString == nil) { ... }
NSURL *url = [NSURL URLWithString:urlString];
if (url == nil) { ... }
NSError* error = nil;
NSData *imageData = [[NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
if (error) {
NSLog(@"%@", [error localizedDescription]);
[error release];
}
UIImage *thumb = [UIImage imageWithData:imageData];
关于ios - 来自 NSData 的 UIImage 在 iPad2 上工作正常但在 iPad1 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6275844/