views:

41

answers:

1

I have an entity which stores generic information about an event. In the entity, the date the event took place is stored.

My view hierarchy is such that I want the user to be able to select a year, which loads another view requesting the month in the selected year. This finally opens a view with a record of all the events that took place within that month and year. If the user selects and event, they can then either edit or view it's details. This is being implemented in a tableview/navigation controller.

i.e. 2010
     2009 --> Dec
     2008     Nov --> Event 3
     2007     Oct     Event 2
                      Event 1 --> Detail View

As the user adds new events, it is very likely that the month and year will change. I don't want to create an array for months or years unless an event actually took place, and I guess I would decide what array to store the entry in when it is loaded by referencing the event date and using some programming logic to put it into the correct month and year array. However, my programming experience is letting me down somewhat, and I'm struggling to come up with an implementation that will allow me to dynamically create an unknown number of arrays. Please could somebody explain how to go about this, or point me in the direction of an article/post that demonstrates this? As I have had no luck with searching, I'd like to know if it is even possible?

+1  A: 

You can use NSMutableDictionary. You have a big dictionary contains

key -> value    
year -> NSDictionary           
        month -> ...

Then when you have a new year, you can put into the NSDictionary, if your year is already there, you can look up it and put into the month dictionary...

vodkhang
I hadn't thought of that. So, as I understand it, you suggest the following:So I would set the key to be the year. The object for that key would be another mutable dictionary.The next dictionary key would be the month. The object would be a mutable array.The mutable array would then contain the event objects.
churchill614
yeah, kind of like that:)
vodkhang