テーブルセルに xml リストからタイトルとイメージ URL を入力したいと考えています。タイトル (NSMutableDictonary *sections) と imageURL (NSMutableDictonary *sectionsImg) をそれぞれ 2 つの NSMutableDictionary に保存することができました。
/*******This is in viewDidLoad***/
Directory *allDirectory = [appDelegate.directories objectAtIndex:0];
for (allDirectory in appDelegate.directories)
{
NSDictionary *dica = [NSDictionary dictionaryWithObject:allDirectory.dirTitle forKey:@"dirTitle"];
NSDictionary *dico = [NSDictionary dictionaryWithObject:allDirectory.imageURL forKey:@"imageURL"];
[dirName addObject:dica];
[dirImage addObject:dico];
//NSLog(@"dic of items : %@",dirImage);
}
for (allDirectory in appDelegate.directories)
{
//retrieve the first letter from every directory title (dirTitle)
NSString * c = [allDirectory.dirTitle substringToIndex:3];
NSString * m = allDirectory.imageURL;
found = NO;
find = NO;
for (NSString *str in [self.sections allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
for (NSString *stra in [self.sectionsImg allKeys])
{
if([stra isEqualToString:m])
{
find = YES;
}
}
if (!found)
{
[self.sections setValue:[[NSMutableArray alloc]init] forKey:c ];
[self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
}
if (!find)
{
[self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
}
}
for (NSDictionary *directory in dirName)
{
[[self.sections objectForKey:[[directory objectForKey:@"dirTitle"] substringToIndex:3]] addObject:directory];
//NSLog(@"hehehe have : %@",sections);
}
for (NSDictionary *directoryImg in dirImage)
{
//[[self.sectionsImg objectForKey:[[directoryImg objectForKey:@"imageURL"] substringFromIndex:0]] addObject:directoryImg];
[[self.sectionsImg objectForKey:[directoryImg objectForKey:@"imageURL"]] addObject:directoryImg];
//NSLog(@"HOHOHO have : %@",sectionsImg);
}
そして cellForRowAtIndexPath で辞書を宣言します
NSDictionary *dictionary = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"dirTitle"];
しかし、imageURLの辞書を宣言しようとしたとき
NSDictionary *dictionaryImg = [[self.sectionsImg valueForKey:[[[self.sectionsImg allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
それは私にエラーを与えます: キャッチされていない例外 'NSRangeException' によるアプリの終了、理由: ' * -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
理由はありますか?XMLのタイトルとURLを取得して表示できるロジックは同じであると想定されています。タイトルは取得できますが、imageURL は取得できません。助けていただければ幸いです。