我有一個視圖,其中有一個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];
}
}
...並確保呼叫取消連接 –
我該如何去做這件事? – boostedz06
[connection setDelegate:nil]; –