xml list에서 title 및 imageurl로 tablecell을 채우고 싶습니다. 제목 (NSMutableDictonary * sections)과 imageURL (NSMutableDictonary * sectionsImg)을 각각 2 개의 NSMutableDictionary에 저장합니다.URL 이미지 인 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"];
를 선언하지만 난 이미지 URL
NSDictionary *dictionaryImg = [[self.sectionsImg valueForKey:[[[self.sectionsImg allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
에 대한 사전을 선언하려고 할 때 그것은 나에게 오류 제공합니다 인해 캐치되지 않는 응용 프로그램 종료를 예외 'NSRangeException', 이유 : '* - [NSMutableArray objectAtIndex :] : 인덱스 1 바운드를 넘어서 s [0 .. 0] '
왜 그런가? 논리는 XML 제목과 URL을 검색하여 표시 할 수있는 위치와 동일해야합니다. 제목은 검색 가능하지만 imageURL은 검색 할 수 없습니다. 도움말을 깊이 감사드립니다!
그리고 URL에 배치 된 이미지를 사용하여 정교하게 설명 했으므로 설명 된 내용을 찾을 수 있도록 답변을 편집했습니다. – Joetjah