Using an objects date (without time) for a table header instead of an objects date and time (iphone)

Posted by billywilliamton on Stack Overflow See other posts from Stack Overflow or by billywilliamton
Published on 2010-05-14T20:19:17Z Indexed on 2010/05/14 20:24 UTC
Read the original article Hit count: 176

Filed under:
|
|
|
|

I've been working on an iphone project and have run into an issue. Currently In the table view where it displays all the objects, I use headers based on the objects datePerformed field. The only problem is that my code apparently creates a header that contains both the date and time resulting in objects not being grouped solely by their date as I intended, but rather based on their date and time. I'm not sure if it matters, but when an object is created I use a date picker to pick the date, but not the time. I was wondering if anyone could give me any suggestions or advice.

Here is the code where i set up the fetchedResultsController

- (NSFetchedResultsController *)fetchedResultsController {

if (fetchedResultsController != nil) {
    return fetchedResultsController;
}

// Create and configure a fetch request with the Exercise entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

// Create the sort descriptors array using date and name
NSSortDescriptor *dateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"datePerformed" ascending:NO];
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:dateDescriptor, nameDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

// Create and initialize the fetch results controller
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"datePerformed" cacheName:@"Root"];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;

// Memory management calls
[aFetchedResultsController release];
[fetchRequest release];
[dateDescriptor release];
[nameDescriptor release];
[sortDescriptors release];

return fetchedResultsController;

}

Here's where I set up the table header properties

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// Display the exercise' date as section headings.
return [[[fetchedResultsController sections] objectAtIndex:section] name];

}

Any suggestions welcome. Thanks for your time.

-Billy Williamton

© Stack Overflow or respective owner

Related posts about iphone

Related posts about table