我正在将密钥加载到 ios 中的选择器控件中。我的问题是我无法按字母顺序排序键。
代码从 UnSorted: Nordfyn, Svendborg, Nyborg, Langeland, Assens, Kerteminde, Middelfart, Odense, Ærø, Faaborg-Midtfyn, 到 Sorted: Ærø, Svendborg, Nyborg, Langeland, Kerteminde, Nordfyn, Middelfart, Assens, Odense , 法博格-米特芬。
NSBundle *KSbundle = [NSBundle mainBundle];
NSURL *KSplistURL = [KSbundle URLForResource:@"KommunerStedtillæg"
withExtension:@"plist"];
NSDictionary *KSdictionary = [NSDictionary
dictionaryWithContentsOfURL:KSplistURL];
NSArray *KSkeys = [[KSdictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSMutableDictionary *KSnewDict = [NSMutableDictionary dictionary];
for (id key in KSkeys)
[KSnewDict setObject:[KSdictionary objectForKey:key] forKey:key];
kommunerKeys = [KSnewDict allKeys];
kommunerValues = [KSnewDict allValues];