开发者

How to sort an NSArray of keys?

I have an NSArray of keys from an NSDictionary like this:

NSArray *array = [[NSArray alloc] initWithArray:[myDict allKeys]];
[array sortedArrayUsingSelector:@selector(compare:)];

Why doesn't t开发者_开发百科he array get ordered?


I think its useful for you

NSDictionary *stateZip;
NSArray *states;
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];         
self.stateZip=dictionary;
[dictionary release];


NSArray *component = [self.stateZip allKeys];
NSArray *sorted =[component sortedArrayUsingSelector:@selector(compare:)];
self.states=sorted;

ragards, CNSivakUmar


Heyy Try this....

NSSortDescriptor *lastNameSorter = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];

so do I put this in the data.h/m file as the NSMutablearray is created with the data or in the viewcontroller.h/m file as I need to display the data in a table?


This might be helpful:

NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@”self” ascending:YES];
[array sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
[sortDesc release];

For More information, have a look at

  1. NSSortDescriptor
  2. Sorting-NSArrays
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜