我正在使用此代码从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元素,但我需要以字母顺序显示数据。
答案 0 :(得分:0)
更改此行:
sortedCountries =[[NSArray alloc]initWithArray:[dict objectForKey:@"Name"]];
为此:
NSArray *array = [dict objectForKey:@"Name"];
sortedCountries = [array sortedArrayUsingSelector:@selector(compare:)];