开发者

Date wise sectioning of a UITableView

开发者 https://www.devze.com 2022-12-18 13:32 出处:网络
Suppose I have a UITableViewController with an array \"history\" as data source. The array consists of an undefined number of NSDictionaries. Each dictionary contains the following keys: term (NSStrin

Suppose I have a UITableViewController with an array "history" as data source. The array consists of an undefined number of NSDictionaries. Each dictionary contains the following keys: term (NSString), date (NSDate) and id (NSNumber).

I would like to map the contents of the history array according to the date values each dictionary has, i.e. I need to dynamically create sections, named and sorted according to the date values of each dictionary (the iPhone app wikipanion does this in its history vi开发者_如何转开发ew). Is there a best practice to do this? Otherwise I would just read out each date object, sort them into another dictionary, etc...


Best practice is to 'group by YYYY-MM-DD' and then 'sort by YYYY-MM-DD HH:MM:SS'. So this involves some simple grouping of your dictionaries into arrays. Now that you have an array of arrays you can sort those simply by date.

0

精彩评论

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