Tableview section By Date

2019-09-08 08:19发布

问题:

How to group data in the tableview by date in Xcode?

回答1:

Have a look at the DateSectionTitles sample app. It demonstrates a tableview with date cells grouped by the month. It is based on CoreData.



回答2:

First of all you need to find reasonable date groups: month, week, year-month combination etc. After that you'll have to find a method which can determine which of your cell has to go to which group/section, described as an NSIndexPath. numberOfSections as well as numberOfRowsInSection has to reflect your grouping idea. With the UITableViewDataSource protocol you can provide the names for your sections with titleForHeaderInSection:.