我在NavigationController中遇到了我的UITableView问题。 当我向表中添加数据时,我使用另一个类下载图像以显示在该表中,而所有这些都很有效,但如果在图像中间下载,我会回到导航控制器应用程序中的上一个视图崩溃。
这是我的代码进一步解释
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Set appIcon and clear temporary data/image
UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
UIImage *appIcon;
if (image.size.width != kAppIconHeight && image.size.height != kAppIconHeight)
{
CGSize itemSize = CGSizeMake(125, 85);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
appIcon = UIGraphicsGetImageFromCurrentImageContext();
///UIGraphicsEndImageContext();
}
else
{
appIcon = image;
//self.appRecord.appIcon = image;
}
self.activeDownload = nil;
// Release the connection now that it's finished
self.imageConnection = nil;
// call our delegate and tell it that our icon is ready for display
if(delegate != nil)
[delegate appImageDidLoad:self.indexPathInTableView imaged:appIcon ];
[image release];
}
appImageDidLoad是我的UITableView视图中存在的方法。
有没有办法可以检查UITableView是否在我的imagedownload类中有效,所以我知道不发送图像。
提前致谢。
答案 0 :(得分:1)
崩溃是由于代表在图像准备好之前获得释放!
在ViewWillDisappear
// terminate all pending download connections
NSArray *allDownloads = [self.imageDownloadsInProgress allValues];
[allDownloads performSelector:@selector(cancelDownload)];
答案 1 :(得分:1)
这是此次崩溃的解决方案。
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
// terminate all pending download connections
NSArray *allDownloads = [self.imageDownloadsInProgress1 allValues];
[allDownloads makeObjectsPerformSelector:@selector(cancelDownload)];
}