开发者

NSArray of values, want to display alphabetically in sections. How to distribute in correct sections?

开发者 https://www.devze.com 2023-04-02 04:26 出处:网络
Sorry, I\'m not sure how to search for the answer to this, but I\'m sure it\'s out there. I have a large NSArray of strings in alphabetical order. I want to add them to a uitableview and have them di

Sorry, I'm not sure how to search for the answer to this, but I'm sure it's out there.

I have a large NSArray of strings in alphabetical order. I want to add them to a uitableview and have them distributed correctly in each section by the fir开发者_如何学Cst letter. I have the sections set up, but I'm not sure how to tell my tableview to add to the next section when the object starts with the next letter in the alphabet. Thanks for any help! It's much appreciated!


Hy

You must parse the array manually, and then tell the tableView - via delegate method - the number of sections, and items. If I were you, I would place it in a dictionary, and the keys are numbers, which are represents sections, and the values are an array of the titles. It is easy to use. You only have to parse the original array.


There is an example that describes what you want: http://www.devx.com/wireless/Article/43374/1763


I think using an NSDictionary is much more convenient in this case. An NSDictionary inherently allows you to store your data alphabetically.

Vocabulous is a great example project for this use case.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号