Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:25:40+00:00 2026-06-14T06:25:40+00:00

I’ve been troubleshooting this issue for several hours now, no success so far. I’ve

  • 0

I’ve been troubleshooting this issue for several hours now, no success so far. I’ve read all question here on SO that might be related to my problem.

I’ve got two Entities (A, B) that are connected to each other in a tree-like structure via a one-to-many-relationship like this: A <—>> B.

There’s a UITableViewController backed by a NSFetchedResultsController to show all objects of entity B that are related to a selected object of entity A. I’m using the predicate for that:

    - (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"B" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

[fetchRequest setFetchBatchSize:20];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"controlDate" ascending:NO];
NSArray *sortDescriptors = @[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];

NSMutableArray *subpredicates = [NSMutableArray array];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"isRelatedTo = %@", selectedObjectOfA];
[subpredicates addObject:predicate1];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"syncStatus != %d", ObjectDeleted];
[subpredicates addObject:predicate2];

NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
[fetchRequest setPredicate:predicate];

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return _fetchedResultsController;
}

Everything works fine for adding, deleting and editing objects. The table gets updated accordingly. My class conforms to NSFetchedResultsControllerDelegate and the delegate methods are boilerplate.

But I want the user to be able to able to cycle through all objects of Entity A by tapping “up”/”down” buttons without going back in the navigation stack (like one can cycle through the emails directly in the Mail app). The number of relatedObjects of B varies depening on the selected Object of A (between none and and lets say 20).

And here comes the problem:
My intention is to refresh the FRC’s results by changing the predicate (not it’s structure or syntax but only the value of the ‘selectedObjectOfA’ and calling

[self.fetchedResultsController performFetch:&error];

All the rest should be done by the FRC.

First question would be: is this approach correct?

Here are the scenarios I’ve already tried:

  • just setting ‘selectedObjectOfA’ to a new value and calling performFetch always shows the same result (because the fetchRequest and the predicate aren’t being updated I suppose)

  • ‘resetting’ the FRC’s fetchrequest like this

    NSMutableArray *subprediactes = [NSMutableArray array];
    NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"isRelatedTo = %@",    self.selectedObjectOfA];
    [subprediactes addObject:predicate1];
    NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"syncStatus != %d", ObjectDeleted];
    [subprediactes addObject:predicate2];
    
    NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subprediactes];
    [self.fetchedResultsController.fetchRequest setPredicate:predicate];
    

updates the FRC and returns the correct data as I suppose but the app crashes with a incorrect number of rows

'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

because the NSFetchedResultsController delegate methods don’t get called. Thus the number of rows in the tableView don’t get adapted to the new results (the number of returned objects is correct according to the error message).

The second question is then: why does the delegate fire when adding/deleting objects but not after the predicates (and therefore the results) have changed?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:25:41+00:00Added an answer on June 14, 2026 at 6:25 am

    You have to call

    [tableView reloadData];
    

    after modifying the fetch request. A fetched results controller tracks only changes that occurred after performFetch.

    You could try the following to get an animated update of the table view (but I haven’t tried that yet, so I am not sure if it works):

    • Call [tableView beginUpdates].
    • Use [tableView deleteRowsAtIndexPaths:...] to delete all “old” rows.
    • Update the fetched results controller fetch request.
    • Call [fetchedResultsController performFetch:...].
    • Call [tableView insertRowsAtIndexPaths:...] for all objects of [fetchedResultsController fetchedObjects] to insert all “new” rows.
    • Call [tableView endUpdates].
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.