2012-09-28 61 views
0

在我的應用我實現延遲加載了一類我稱之爲ThumbDownloader的iOS委託崩潰

開始圖像下載,我的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快速離開WH ILE圖像被下載,應用程序崩潰與:

-[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實例迭代他們的代表設爲零,但是當我嘗試,它崩潰,以及...這樣的:

- (void)dealloc 
{ 

    for(ThumbDownloader *thumbDownloader in imageDownloadsInProgress) 
     if(thumbDownloader !=nil && thumbDownloader.delegate!=nil) 
      thumbDownloader.delegate = nil; 

    ..... 

回答

0

如果您使用一套圖像UIImageView的代碼,你應該嘗試使用從這個問題AFNetworking框架0類。您只需設置[image setImageWithUrl:@"http://myImage"];

+0

對不起,這不幫助我。我需要知道,用我現有的代碼,如何設置委託,以零因此它不崩潰 – boostedz06