ios - 来自 NSData 的 UIImage 在 iPad2 上工作正常但在 iPad1 上不工作

标签 ios ipad asynchronous uiimage nsdata

我刚遇到一个很奇怪的问题。 我目前正在开发一个应用程序,它以异步方式从远程主机加载图像,然后显示它们。

以下代码正在后台线程中执行,通过 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/

相关文章:

ios - 在 Xcode 9 的上下文中,“对象”对于类型查找是不明确的

ios - 在 Swift 中 CloudKit 异步操作完成时设置 UILabel 文本

iphone - 如何使用 MKStoreKit 恢复购买

javascript - 如何在每次循环内调用小程序方法时更新进度条(不仅仅是循环完成时)?

c# - WPF 如何处理等待 Async/Await 响应的字段?

ios - 泄漏和如何处理

ios - 使用适用于 iOS 的 Google Maps SDK 后应用程序大小增加

ios - 我的 viewController 没有正确显示

ios - iPad 需要启动图像

javascript - 向 Mongo 发送并行请求,并在所有请求完成后继续