我正在开发我的第一个IOS应用程序。该应用程序通过PHP网页从数据库下载并显示数据。这一切工作正常。我也从同一个Web服务器抓取图像以显示在UIImageView中。这一切都可以在模拟器上正常工作。在设备上显示图像时出现问题
在我的测试设备(3GS)上,一切正常,除非我无法获取下载的图像以显示在我的UIImageView中。
如果没有互联网连接,我可以显示我已经包含在模拟器和设备上的应用程序包中的备用图像。
// Inside My data class Implementation
- (void)setUpTheData
{
--- other code ---
NSURL *myImageURL = [NSURL URLWithString:myImageURLString];
NSData *myImageRawData = [NSData dataWithContentsOfURL:myImageURL];
self.myImageData = myImageRawData;
}
- (NSData*)getTheImageData
{
return _myImageData;
}
// Inside my viewDidLoad
UIImage *theImage = [UIImage imageWithData:[theRemoteData getTheImageData]];
_testImage.image = theImage;
我比较了来自模拟器和设备的图像数据,它们是相同的。
同时仔细检查任何后台进程代码,因为更新UI需要在主线程上发生。异步返回可能导致这种情况?不知道这与它有什么关系,但是当我遇到这样难以解释的奇怪东西时,我发现它通常是线程或同步相关的。 – 2013-02-17 03:57:29
谢谢蒙特。你的第一个建议没有奏效。回到绘图板。我会研究你的其他建议。 – 2013-02-18 01:02:00