gpt4 book ai didi

ios - 如何按字母顺序将plist数据放入 TableView

转载 作者:行者123 更新时间:2023-12-01 16:53:34 24 4
gpt4 key购买 nike

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

最佳答案

更改此行:

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

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

关于ios - 如何按字母顺序将plist数据放入 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13766982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com