0

在我的应用程序中,我正在使用一个名为 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;

    .....
4

1 回答 1

0

如果您使用该代码将图像设置为 UIImageView,则应尝试使用"UIImageView+AFNetworking.h"AFNetworking 框架中的类别来解决此问题。你只需要设置[image setImageWithUrl:@"http://myImage"];

于 2012-09-28T13:55:27.403 回答