遅延読み込みUITableView
に従ってセル画像を読み込んでいます。これがインデックスパスの行のセルのコードです
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 *)パス{
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
フォーマットです。これの何が問題なのですか。助けてください。
ありがとう