I am playing around with the coredatabooks source code example from the apple website, or here. I am trying to set the books copyright date attribute value to replace the author as the tableview section header, and I need the date value to be static, meaning I don't need the time, otherwise all of the date values are different, and no two books objects with the same month day and year copyright date lineup under the same date because the time portion of the date value is changing...
Here is the code from my RootViewController.m file that formats the datepicker date value for display in the section header:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *rawDateStr = [[[fetchedResultsController sections] objectAtIndex:section] name];
//convert default date string to NSDate...
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];
NSDate *date = [formatter dateFromString:rawDateStr];
//convert NSDate to format we want...
[formatter setDateFormat:@"EEEE MMMM d"];
NSString *formattedDateStr = [formatter stringFromDate:date];
return formattedDateStr;
}
That outputs just fine, but it isnt letting me group books with the same copyright month day and year in the same section because again (I am assuming) the date value has the time as well. The actual saving of the date value from the datepicker is done in the EditingViewController.m file as follows:
- (IBAction)save {
// Pass current value to the edited object, then pop.
if (editingDate) {
[editedObject setValue:datePicker.date forKey:editedFieldKey];
}
The save method currently takes the date as-is from the datepicker, so how do I modify that code to first copy the datepicker's date to a local variable and blank out the time in there and then use that value in the setValue statement so it groups correctly? PLEASE HELP! Thanks