So I never GOT how titleForHeaderInSection and, basically, grouped UITableView work. I gave up trying to create one and ended up using plain lists for the moment. I’d appreciate if any of the following points could be explained:
Understanding it…
-
If I want a grouped UITableView I understand I need to return how many groups (sections) I want in it using numberOfSectionsInTableView. Say, return 3.
-
Then I’ll need to return how many rows I’ll have in each different section, right? I can do it in numberOfRowsInSection. Say, return 2 for the first section, 4 for the second, 6 for the third, right?
-
If I want each of those sections to have a different title, I’ll need to use titleForHeaderInSection, but I find it tricky to use. However it seems I just need to get the section integer and set the title to my sections’ array using objectAtIndex, right?
-
In cellForRowAtIndexPath do I need to do anything at all regarding sections or how I’ll show the cells? Seems I don’t, but I’m not sure…
Problem
My data is structured like that (it’s a JSON array containing dictionaries in each array entry):
ArrayItemOne
DictionaryKeyOne:DictionaryValueOne
DictionaryKeyTwo:DictionaryValueTwo
ArrayItemTwo
DictionaryKeyOne:DictionaryValueOne
DictionaryKeyTwo:DictionaryValueTwo
ArrayItemThree
DictionaryKeyOne:DictionaryValueOne
DictionaryKeyTwo:DictionaryValueTwo
My sections titles are actually the DictionaryValueTwo of all 3 ArrayItemFoo above, and it’s dynamic, I don’t know how many of them will be today or tomorrow, it comes from the JSON. Then I create a unique set of them and count it. That’s my numberOfSectionsInTableView.
But how in hell I’ll get my rows grouped by this DictionaryValueTwo in each different section, ONLY if their DictionaryValueTwo matches the section header? Right now I can’t control what rows will be in each section, it’s a mess and I’m confused.
Picture this: all events have a date, my sections are the non-duplicate events dates, but my events need to show up only in the sections matching their dates. That’s it. I’m too stupid to understand how grouped UITableView works to do it…
My code
I have coded a UITableView using plain lists already, it has some commented out stuff for grouped lists, if it helps to understand my question: http://github.com/caio1982/CorreCuritiba/blob/master/iOS/CorreCuritiba/CorreCuritiba/CCMasterViewController.m
Again: some code exemplifying the explanations would be great but it’s not mandatory, I really am looking to understand grouped UITableViews, the concept, the mechanism.
And yes, I’ve searched all over and didn’t find anyone with the same problem I’m facing.
Gustavo Boiko’s patches sort of explains well enough how it’s supposed to work. My data structure was wrong after all: https://github.com/caio1982/CorreCuritiba/pull/3