data structure for sectioned table view
I was reading an article "sectioned table view", and noticed that the author used a NSArray of NSDictionary of NSArray to store the data.
What is the benefit of doing this, why not simp开发者_StackOverflow中文版ly use a NSArray of NSArray?
There is nothing inherent in the UITableView sectioning that requires the use of the dictionary. As long as you can accurately count the number of sections and the number of rows in each section, the tableView is happy. He could have used arrays. Everyone has their favorite data structure; I guess this guy likes dictionaries.
A correct way to reason about this is you need a collection of sections. Each section entry will hold some section metadata and the list of items. So at top level you can have NSArray holding section. Each entry in the array can be a dictionary holding the metadata (such as title, item counts, date etc.). One of the key in dictionary would items, which would again be an NSArray of items.
NSArray<Section>
|
NSDictionary
| - title
| - ..
| - items
|
NSArray<Item>
精彩评论