I use apple’s code IconDownloader to download the image,I have added the IconDownloader file,but it doesn’t work.
- (void)startIconDownload:(UserInfo *)userImageObject forIndexPath:(NSIndexPath *)indexPath
{
IconDownLoader *iconDownloader = [imageDownloadsInProgress objectForKey:indexPath];
if (iconDownloader == nil)
{
iconDownloader = [[IconDownLoader alloc] init];
iconDownloader.appRecord = userImageObject;
iconDownloader.indexPathInTableView = indexPath;
iconDownloader.delegate = self;
[imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
NSLog(@"indexPath:%@",indexPath);
NSLog(@"iconDownloader:%@",iconDownloader);
NSLog(@"imageDownloadsInProgress:%@",[imageDownloadsInProgress objectForKey:indexPath]);
[iconDownloader startDownload];
[iconDownloader release];
}
}
// called by our ImageDownloader when an icon is ready to be displayed
- (void)appImageDidLoad:(NSIndexPath *)indexPath
{
IconDownLoader *iconDownloader = [imageDownloadsInProgress objectForKey:indexPath];
NSLog(@"%@",imageDownloadsInProgress);
if (iconDownloader != nil)
{
UITableViewCell *cell = [myTableView cellForRowAtIndexPath:iconDownloader.indexPathInTableView];
// Display the newly loaded image
cell.imageView.image = iconDownloader.appRecord.image;
}
}
this is my log:
1970-01-13 14:44:32.-714 Mo[5726:307] indexPath:<NSIndexPath 0x275260> 2 indexes [0, 0]
1970-01-13 14:44:32.-694 Mo[5726:307] iconDownloader:<IconDownLoaderTan: 0x2c57a0>
1970-01-13 14:44:32.-689 Mo[5726:307] imageDownloadsInProgress:(null)
we can see the problem is imageDownloadsInProgress dictionary is null,why?but the key(indexPath) and the object(iconDownloader) are not null.who can tell me why?thanks in advance.
I have defined the imageDownloadsInProgress in my .h file:
NSMutableDictionary *imageDownloadsInProgress;
two issues i think are in your code.
1)
imageDownloadsInProgressmight not be initialized ..so initialize it in your vieDidLoad (can’t add objects without initializing)
2) You are setting
index pathas a key for the object in the dictionary…i believe you can only setNSStringas a key so make a string with the index path usingNSString stringWithFormat:and then store it in the dictionary