Actually i’m using only one section. I sort my data stored in core data by date.
I want to have two sections (latest and history). In my first section “latest” I want to put my latest date and in the other section “history” i want to put other dates sorted by date.
My table is editable and I’m using NSFetchedResultsController.
Here is my sample code for numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Info"
inManagedObjectContext:self.managedObjectContext]];
// Define how we want our entities to be sorted
NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc]
initWithKey:@"date" ascending:NO] autorelease];
NSArray* sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
NSString *lower = [mxData.name lowercaseString];
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(name = %@)", lower];
[fetchRequest setPredicate:predicate];
NSError *errorTotal = nil;
NSArray *results = [self.managedObjectContext executeFetchRequest:fetchRequest error:&errorTotal];
if (errorTotal) {
NSLog(@"fetch board error. error:%@", errorTotal);
}
return [results count];
[fetchRequest release];
[results release];
}
You need to modify your designated “
UITableViewDataSource” object to return “2” for the “numberOfSectionsInTableView:“ method.Then you need to return the right thing in your “
tableView:cellForRowAtIndexPath:“ method, depending on the section designated in the index path.If you want an optional section title (e.g. “History” or “Latest”), you can also return an array of section titles via
sectionIndexTitlesForTableView:.