Нов съм в програмирането на iOS. Трябва да сортирам ключовете си в моя NSDictionary или по-скоро да обърна реда на ключовете си.
Какви са текущите ми ключове в момента;
о! И аз нямам стойности за моите ключове, тъй като те са извадени от моя XML.
NSDictionary (наречен GradDict);
2012 S1
2012 S2
Искам да е така;
2012 S2
2012 S1
Ето моите кодове за сортиране;
В parserDidEndDocument:
NSEnumerator *enumerator = [gradDict keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
NSLog(@"Key:%@",key);
NSLog(@"%@", [gradDict objectForKey:key]);
}
self.sort = [key sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
В cellForRowAtIndexPath:
ModuleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ModuleCell"];
if (!cell)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"ModuleCell" owner:nil options:nil] objectAtIndex:0];
}
NSString *period = [self.sort objectAtIndex:indexPath.section];
NSMutableArray *periodArray = [gradDict objectForKey:period];
Module *m = [periodArray objectAtIndex:indexPath.row];
[cell.moduleNameLabel setText:[m moduleName]];
[cell.moduleCreditLabel setText:[[NSString alloc] initWithFormat:@"%d", [m moduleCredits]]];
[cell.moduleGradeLabel setText:[m moduleGrade]];
cell.contentView.backgroundColor = [UIColor colorWithRed:0.75 green:0.93 blue:1 alpha:1];
[self.tableView setSeparatorColor:[UIColor colorWithRed:0.55 green:0.55 blue:0.55 alpha:1]];
return cell;
Грешно ли правя сортирането? И как да направя cellForRowAtIndexPath?