我正在UITableView
根据延迟加载加载单元格图像。这是我在 indexpath 处的行单元格代码
else if (tableView.tag==4)//All Songs
{
cell4=(SongCell *)[tableView dequeueReusableCellWithIdentifier:@"SongCell"];
if (cell4 == nil) {
NSArray *nib =[[NSBundle mainBundle]loadNibNamed:@"SongCell" owner:self options:nil];
cell4=[nib objectAtIndex:0];
}
[cell4 setSelectionStyle:UITableViewCellSelectionStyleNone];
cell4.lblSong.text=[[arrSongList objectAtIndex:indexPath.row] valueForKey:@"SONGTITLE"];
cell4.lblArtist.text=[[arrSongList objectAtIndex:indexPath.row] valueForKey:@"ARTISTNAME"];
if ([dicSongimages valueForKey:[[arrSongList objectAtIndex:indexPath.row] valueForKey:@"SONGIMG"]]) {
cell4.imgSong.image=[dicSongimages valueForKey:[[arrSongList objectAtIndex:indexPath.row] valueForKey:@"SONGIMG"]];
[cell4.activityIndicator stopAnimating];
cell4.activityIndicator.hidden=YES;
}
else
{
if (!isDragging_msg && !isDecliring_msg)
{
[dicSongimages setObject:[UIImage imageNamed:@"placeholder.png"] forKey:[[arrSongList objectAtIndex:indexPath.row] valueForKey:@"SONGIMG"]];
cell4.activityIndicator.hidden=NO;
[cell4.activityIndicator startAnimating];
[self performSelectorInBackground:@selector(downloadImage:) withObject:indexPath];
}
else
{
cell4.imgSong.image=[UIImage imageNamed:@"placeholder.png"];
cell4.activityIndicator.hidden=YES;
[cell4.activityIndicator stopAnimating];
}
}
[cell4.btnTick addTarget:self action:@selector(tickButtonTapped:) forControlEvents:UIControlEventTouchUpInside] ;
[cell4.btnAddtoMyList addTarget:self action:@selector(topLeft:) forControlEvents:UIControlEventTouchUpInside];
return cell4;
}
此方法用于从这些 URL 下载图像。
-(void)downloadImage:(NSIndexPath *)path{
if(path.row<[arrSongList count])
{
NSString *str=[[arrSongList objectAtIndex:path.row]valueForKey:@"SONGIMG"];
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]];
[dicSongimages setObject:img forKey:str];
[tblSongs performSelectorOnMainThread:@selector(reloadData) withObject:@"TAG_4" waitUntilDone:NO];
}
我的问题是
[dicSongimages setObject:img forKey:str];
它说正在崩溃
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value
但是当我通过浏览器访问该链接时,图像显示正常。所有这些图像都是.jpg
格式。这有什么问题。请帮助我。
谢谢