我正在从服务器获取图像的URL,并使用: NSData *data1 1= NSData dataWithData:UIImagePNGRepresentation(img);data1 writeToFile:pngFilePath原子地:是;
但是当我在模拟器上完成过程后检查它们时,有些图像被破坏了。因此,这些图像没有显示在应用程序的任何需要。
请查看附加的图像,因为一些图像已损坏。

更新
我在循环中调用一个方法,该方法从服务器并行和didFinishLoading中获取图像,我正在执行以下操作: UIImage *img = UIImage imageWithData:self.data;
NSArray *split = [self.strImageName componentsSeparatedByString:@"/"];
int arrCount=[split count];
NSString *imageName=[split objectAtIndex:arrCount-1];
NSString *docDirec = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath=nil
pngFilePath = [NSString stringWithFormat:@"%@/Thumbs/%@",docDirec,imageName];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(img)];
[data1 writeToFile:pngFilePath atomically:YES];
[self.data release]; //don't need this any more, its in the UIImageView now
self.data=nil;发布于 2012-06-26 12:51:47
我有类似的问题,我用下面的代码解决了这个问题
- (void)viewWillDisappear:(BOOL)animated
{
if (self.m_objWebManager != nil)//Webmanager is class for downloading the images as a background thread
{
[self.m_objWebManager cancelCommunication];
[self.m_objWebManager release];
self.m_objWebManager = nil;
}
}https://stackoverflow.com/questions/11207121
复制相似问题