Note (I see that you are not using fetchResultController, and I recommend using it, as it will help you with this task and other tasks with a table view displaying the main data objects).
With fetchResultController:
You must add the totalAmount NSString to the object of your choice (the object you get in the fetchResultController class).
Then add the add operation to the class. inside, create your calculation to get the total amount as a string.
-(NSString*)totalAmount{ NSInteger amount = 0;
and then in the resulting selection controller pass totalAmount as the path to the key of your section, this will return the string totalAmount for each section:
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:@"totalAmount" cacheName:nil];
Then edit the section header methods so that the table view works correctly:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
finally, set the quantity text for each section from the sample result controller:
- (NSString *)controller:(NSFetchedResultsController *)controller sectionIndexTitleForSectionName:(NSString *)sectionName { return sectionName; }
source share