iOS NSURLConnection委托问题
我有一个视图,其中有一个UITableView,我懒加载图像。我有一个名为ThumbDownloader类,我初始化一个NSURLConnection的,并在完成加载图像时connectionDidFinishLoading被称为内connectionDidFinishLoading,我作出这样回我的主要观点进行呼叫:iOS NSURLConnection委托问题
[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的委托。
在ThumbDownloader类的dealloc方法只需添加
[connection cancel]
。这将取消正在进行的下载并阻止消息被调用。
我已经在ThumbDownloader中的dealloc中调用连接取消和连接释放。问题是,我觉得我需要释放thumbdownloader本身。 – boostedz06
我假设你在viewDidUnload方法中调用[imageDownloadsInProgress release]。 – Shashikanth
好吧,我正在调用[imageDownloadsInProgress release]在我的主视图的dealloc中。现在不是viewDidUnload已弃用?我正在使用ios6 – boostedz06
...并确保呼叫取消连接 –
我该如何去做这件事? – boostedz06
[connection setDelegate:nil]; –