在我的应用中,我正在使用名为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实例以将其委托(delegate)设置为nil,但是当我尝试使其崩溃时,也是如此……
- (void)dealloc
{
for(ThumbDownloader *thumbDownloader in imageDownloadsInProgress)
if(thumbDownloader !=nil && thumbDownloader.delegate!=nil)
thumbDownloader.delegate = nil;
.....
最佳答案
如果使用该代码将图像设置为UIImageView,则应尝试使用AFNetworking框架中的"UIImageView+AFNetworking.h"
类别来解决此问题。您只需要设置[image setImageWithUrl:@"http://myImage"];
关于ios - iOS代表当机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12640950/