Im stuck with this problem, I have a UITableView and i populate it with data from an NSMutableArray. The Array has the following structure:
<array>
<dict>
<key>Date</key>
<string>2011.18.09 04:17 PM</string>
<key>Value</key>
<string>58.00</string>
</dict>
<dict>
<string>2011.15.09 04:21 PM</string>
<key>Value</key>
<string>0.00</string>
</dict>
</array>
I would like to have a section for each day in the Array. I already figured out how to return the number of dates, and name the section headers, the only problem i am having is returning the number of rows per section and then defining the cells for each row.
Working code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedData.daf"];
NSMutableArray *d = [NSMutableArray arrayWithContentsOfFile:path];
NSMutableArray *test = [d valueForKey:@"Date"];
NSString *g = [[NSString alloc] init];
NSString *s = [[NSString alloc] init];
c = 0;
for (g in test) {
s = [g substringToIndex:[g length]-9];
if (![s isEqualToString:sf]) {
c = c+1;
[dates addObject:s];
}
sf = [g substringToIndex:[g length]-9];
}
return c;
that code counts the different dates and creates an array with the section names. Could anybody help me with defining the number of rows (by counting the number of objects for each day) and by giving the rows the right value in the ´cellForRowAtIndexPath´ method.
Ok, i finally found a solution. It is actually pretty easy to understand. To return the numbers of sections, i need to find out how many different dates there are in the array. For the number of rows i need to know how many values there are for each day. so here is what i did:
Rows:
Sections:
Titles: