Sectioning a tableview by dates from a dictionary

后端 未结 2 811
庸人自扰
庸人自扰 2021-01-26 11:57

I have a dictionary that contains a key/value pair of a Date that contains an array of my custom object Meals grouped together by the same dates.

Meal Object:

         


        
2条回答
  •  自闭症患者
    2021-01-26 12:35

    In your datamodel, you take the dictionary that you have with one day per entry, take the keys as an array, and sort the array.

    Your tableview has as many sections as that array has entries. You create the title of each section from the date. For every section, you take the array of meals from the dictionary, so each section has a different number of rows, and the data from eac row is taken from one row of the arrays.

    For example, to get the data for section 3, row 5, you take the date from your array of dates at index 3, you lookup the date in the dictionary and get an array of meals, and the meal at index 5 provides the data.

提交回复
热议问题