0

I have this data that I'd like to save to plist. MONTH and DAY are the system date integers. I know how to get them.

 MONTH
  DAY
   int, string, int

Example:

 5
  25
   10, text, 50

I have a UITableView in which I must import the data on this way:

If the system month is 3, search the plist for the key 3 and populate the table with only days of the month 3.

What is the best approach for this?

EDIT:

The year is not important. In the table, it should be a list of months, and when pressed it should list all the days associated with the particular month. And every day should have all the data associated to particular day.

I am confused on how to structure the data in the plist.

maxus182
  • 161
  • 1
  • 1
  • 10

2 Answers2

0

NSDate is one of those Objective C objects that needs developer intervention to archive (or code) into a plist file.

And your question is still so broad, I'm not 100% certain what the best approach is in your specific case. Do you want to display "2012" in one cell and then "5" in an indented cell below this? In that event, you might want to load the date from the plist into a custom object that has NSDate property. Or maybe you will want to have separate "year" and "month" values associated with a single object that has multiple table view cells listed with it. Or maybe you want to have all of this listed out into a single custom table view cell per date.

Take a look at other questions on StackOverflow (like this one) that describe how to save & load NSDate objects and then consider how to make use of this in your UITableViewController.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
0

Looks like this thread has some good information on saving your NSDictionary as a plist:

Save NSDictionary to plist

As for displaying your results in the table view, I'm a little confused as to how you are organizing your NSDictionary. In general, you should do something like this:

NSArray *arrayDataForMonthZero = [[NSArray alloc] initWithObjects:@"Your",@"Objects",@"For",@"Section",@"Zero"];
NSArray *arrayDataForMonthOne = [[NSArray alloc] initWithObjects:@"Your",@"Objects",@"For",@"Section",@"One"];
...
NSArray *arrayDataForMonthEleven = [[NSArray alloc] initWithObjects:@"Your",@"Objects",@"For",@"Section",@"Eleven"];

NSDictionary *tableData = [[NSDictionary alloc] initWithObjectsAndKeys:arrayDataForMonthZero,@"0",arrayDataForMonthOne,@"1",...,arrayDataForMonthEleven,@"11"];

Then, you create an NSArray pointer to the data set you want to use. So, if you want to display the third section, just do:

NSArray *tableDataPtr = [tableData objectAtIndex:@"3"];

This will select all the data you just created associated with the third month. Use this object when providing commands to your table view delegate and data source.

Community
  • 1
  • 1
Michael D.
  • 399
  • 4
  • 16
  • You should be able to look at my example and extrapolate the structure from there. You'd be nesting multiple NSDictionaries. The first would have keys matching the months. This would return an NSDictionary with keys matching the days. Finally, that will return the data you want associated with that particular month and day. – Michael D. Jun 01 '12 at 21:36