如何按字母顺序将plist数据导入表视图

时间:2012-12-07 16:24:11

标签: ios

我正在使用此代码从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元素,但我需要以字母顺序显示数据。

1 个答案:

答案 0 :(得分:0)

更改此行:

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

为此:

NSArray *array = [dict objectForKey:@"Name"];
sortedCountries = [array sortedArrayUsingSelector:@selector(compare:)];