表视图从 NSDictionary 加载,但不是按字母顺序加载
我对编程很陌生,但现在正在尝试使用表格视图应用程序。我使用了一些片段,但效果很好。我似乎不明白如何按字母顺序加载表视图,因为这看起来好多了。导航有四个级别,其中前两个是表格视图。所有数据都存储在带有字典的 plist 文件中。我包含了代码。我感觉我错过了一些非常明显的东西,但我似乎无法找出它是什么!谁能帮助我?预先感谢您的宝贵时间!
- (void)viewDidLoad {
// Create the table view data source array from the dictionary property
tableViewData = [[dataForCurrentLevel allKeys] retain];
I am quite new to programming, but now experimenting with a table view app. I used some snippets for it, but it works pretty well. What I can't seem to figure out is how I can load my table view alphabetically, because that looks a lot nicer. The navigation has four levels, from which the first two are table views. All the data is stored in a plist file with dictionaries. I Included the code. I have the feeling I am missing something very obvious, but I can't seem to find out what it is! Who can help me? Thanks in advance for your time!
- (void)viewDidLoad {
// Create the table view data source array from the dictionary property
tableViewData = [[dataForCurrentLevel allKeys] retain];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请仔细阅读@VdesmedT 的回答。只需在将数组传递到表视图之前对其进行排序,如下所示:
Please read answer from @VdesmedT carefully. Just sort your array before passing it to the tableview like:
使用sortDescriptor对数组进行排序
Use sortDescriptor to sort the array
NSDictionaries 是哈希表,因此键实际上是使用其哈希值进行排序的。
例如,您需要使用
sortedArrayUsingSelector:
对结果数组进行手动排序,但 NSArray 类中还有很多其他方法。NSDictionaries are hash tables so the keys are in fact sorted using their hashes.
You need to sort the resulting array manually using
sortedArrayUsingSelector:
for example but there are a lot of other method in the NSArray class.