我有一个有UITableView的视图,在这里我懒于加载图像。我有一个名为ThumbDownloader的类,该类在其中初始化NSURLConnection并在调用connectionDidFinishLoading后完成加载图像后,在connectionDidFinishLoading中,像这样返回我的主视图:
[delegate appImageDidLoad:self.indexPathInTableView];
在我的主视图中,我有一组ThumbDownloader实例。该数组名为:imageDownloadsInProgress
问题是,如果我进入视图并在所有图像下载完成之前迅速退出视图,则会出现僵尸:
-[myApp appImageDidLoad:]: message sent to deallocated instance 0xa499030
我尝试了很多方法在dealloc之类的方式中释放ThumbDownloader实例,但是似乎没有任何效果。
这是我设置实例并将其添加到数组的位置:
- (void)startIconDownload:(Product *)product forIndexPath:(NSIndexPath *)indexPath
{
ThumbDownloader *thumbDownloader = [imageDownloadsInProgress objectForKey:indexPath];
if (thumbDownloader == nil)
{
thumbDownloader = [[ThumbDownloader alloc] init];
thumbDownloader.product = product;
thumbDownloader.imageSizeWidth = 87;
thumbDownloader.imageSizeHeight = 87;
thumbDownloader.indexPathInTableView = indexPath;
thumbDownloader.delegate = self;
[imageDownloadsInProgress setObject:thumbDownloader forKey:indexPath];
[thumbDownloader startDownload];
[thumbDownloader release];
}
}
最佳答案
确保清除NSURLConnection上的委托。