2

我正在使用此代码从 plist 文件中加载一些数据:

self.title =@"Data"; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data"ofType:@"plist"]; 
dict =[NSMutableDictionary dictionaryWithContentsOfFile:path]; 
sortedCountries =[[NSArray alloc]initWithArray:[dict objectForKey:@"Name"]];

我在 tableView 中显示信息:

cell.textLabel.text = [sortedCountries objectAtIndex:indexPath.row];

它正确显示了 plist 元素,但我需要按字母顺序显示数据。

4

1 回答 1

0

改变这一行:

sortedCountries =[[NSArray alloc]initWithArray:[dict objectForKey:@"Name"]];

为了这:

NSArray *array = [dict objectForKey:@"Name"];
sortedCountries = [array sortedArrayUsingSelector:@selector(compare:)];
于 2012-12-07T16:30:51.543 回答