我正在根據延遲加載加載UITableView
單元格圖像。這裏是我的代碼爲索引路徑行的單元格由於未捕獲異常'NSInvalidArgumentException'導致終止應用程序崩潰,原因:' - [__ NSCFDictionary setObject:for
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下載圖像。
- (空)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
但圖像正確顯示w如果我通過瀏覽器訪問該鏈接。所有這些圖像都是.jpg
格式。這有什麼問題。 PLZ幫助我。
感謝
檢查一次placeholder.png圖像有或沒有? – Balu
是的,它在那裏 – iDia
只有當路徑是[0,47] – iDia