Question

I have a problem with UITableView sections. I'm using NSFetchedResultsController to populate table and I've provided sectionNameKeyPath: on initialization.

Basiclly I have a table view with one section but when user taps on cell it is changing one core data attribute and should create second section. I think I've accomplished this but...

When I tap on the first cell it creates new section above (this is how it should be) but when my first tap is on another cell it creates section at the botton of table view. You can preview this on screenshots below:

enter image description here

Here are some Table View delegate methods from my app:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[_fetchedResultsController sections] count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[[_fetchedResultsController sections] objectAtIndex:section] name];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

And my question is: How to manually provide section order?

Was it helpful?

Solution

For this example solution was pretty straight - adding one NSSortDescriptor to existing one in NSFetchedResultsController sort descriptors array.

So now, fetched data is firstly sorted by section and then it is sorted alphabetically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top