Я новичок в программировании 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:)];
В ячейкеForRowAtIndexPath:
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?