UITableView force sectionIndex to update without calling reloadData

306 views Asked by At

I'm modifying my UITableView's data source from a PHChange instance, and this works fine. What I don't understand is I can't get the sectionIndex on the right of the UITableView to update unless you reload the whole UITableView with: reloadData.

Is there any other way to force update the sectionIndex on the right of the UITableView? If I manually call: sectionIndexTitlesForTableView: I confirm that I'm getting back fresh data, however the old sectionIndex on the right doesn't change visually, which is what I need.

Code:

PHFetchResultChangeDetails *changeDetails = [changeInstance changeDetailsForFetchResult:oldFetch];

if (changeDetails)
{
   PHFetchResult *fetchResultAfterChange = changeDetails.fetchResultAfterChanges;

   if (fetchResultAfterChange.count < 1)
   {
       [subArray removeObjectAtIndex:subIdx];

       dispatch_async(dispatch_get_main_queue(),^
       {
            NSIndexPath *path = [NSIndexPath indexPathForRow:subIdx inSection:idx];

            [self.albumsTableView deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];

            // Confirmed data is updating            
            NSLog(@"%@",[self sectionIndexTitlesForTableView:self.albumsTableView]);

            // Does nothing                    
            [self.albumsTableView setNeedsDisplay];
        });
    }
}
1

There are 1 answers

3
Leo On BEST ANSWER

Try this function

- reloadSectionIndexTitles

This method gives you a way to update the section index after inserting or deleting sections without having to reload the whole table.