在我的应用程序中,我使用一个名为ThumbDownloader
的类实现延迟加载要开始图像下载,我的UITableView cellForRowAtIndexPath方法调用此方法:
- (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];
}
}
thumbdownloader类在下载完图像后,调用我的主类(listingView)中的一个名为:
的方法- (void)appImageDidLoad:(NSIndexPath *)indexPath
问题是,如果我输入listingView并在下载图片时快速离开,应用程序会崩溃:
-[listingView appImageDidLoad:]: message sent to deallocated instance 0x3beed10
这是我的dealloc
- (void)dealloc
{
[myTable release], myTable = nil;
[imageDownloadsInProgress release], imageDownloadsInProgress = nil;
[spinView release], spinView = nil;
[mainView release], mainView = nil;
[tableView release], tableView = nil;
[myVs release], myVs = nil;
[filteredVs release], filteredVs = nil;
[toolBar release], toolBar = nil;
[super dealloc];
}
我试图遍历imageDownloadsInProgress中的Thumbdownloader实例,将其委托设置为nil,但是当我尝试它也崩溃时......就像这样:
- (void)dealloc
{
for(ThumbDownloader *thumbDownloader in imageDownloadsInProgress)
if(thumbDownloader !=nil && thumbDownloader.delegate!=nil)
thumbDownloader.delegate = nil;
.....
答案 0 :(得分:0)
如果您将该代码用于UIImageView的设置图像,则应尝试使用AFNetworking框架中的"UIImageView+AFNetworking.h"
类别来解决此问题。您只需设置[image setImageWithUrl:@"http://myImage"];