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 8143887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:13:51+00:00 2026-06-06T13:13:51+00:00

I have nearly tried everything but cannot figure out what is wrong. I have

  • 0

I have nearly tried everything but cannot figure out what is wrong. I have a NSFetchedResultsController and fetch some posts out of core data. Then I have a method where I insert new posts into the same context and save the context. Normally, the didChangeObject: method should be called now, but it does not. I have a similar view controller where I do basically the same on a different table (=nsmanaged object) and there the didChangeObject: method gets called successfully.

What I have tried so far:

  • Created another context just for this view controller

  • Removed the cache of the NSFetchedResultsController

The following method fetches the data out of the core data db and ‘stores’ it into the NSFetchedResultsController (variable: controller).

//reloading newsgroups from coredata
- (void)reloadNewsgroupsFromCoreData
{    
    //creating fetch request
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Post"];

    //sorting by transient date (hour and secons cutted off)
    NSSortDescriptor *sortByDate = [[NSSortDescriptor alloc] initWithKey:@"dateCreatedTransient" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByDate, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];

    //where clause
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ref_subscribed_newsgroup == %@ AND references == nil", self.newsgroup]];

    //setting fetchrequest
    self.controller = [[NSFetchedResultsController alloc]
                       initWithFetchRequest:fetchRequest
                       managedObjectContext:self.context
                       sectionNameKeyPath:@"dateCreatedForSections"
                       cacheName:nil]; //todo, maybe add a cache here!

    //fetch
    NSError *error;
    [self.controller performFetch:&error];

    if (error) {
        NSLog(@"%@", error);
    }
}

Furthermore, according to the documentation I set the delegate of the NSFetchedResultsController to my view controller (this is the same where the aforementioned fetch method is located).

In viewDidLoad:

self.controller.delegate = self;

Then I have implemented the methods from the protocol, also the didChangeObject:

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {    
    UITableView *tableView = self.tableView;   

  // I HAVE ADDED A BREAKPOINT HERE BUT IT NEVER STOPS HERE.

    switch(type) {

        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];

            break;
        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath]
                    atIndexPath:indexPath];

            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray
                                               arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:[NSArray
                                               arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }

}

Then I have another method that stores some posts into core data. I think this is important: This method is invoked via a delegate from another thread. (The server connection invokes it using performSelectorOnMainThread:...)

- (void)storeIntoCoreData:(NSArray*)postsArray
{ 
...
        Post *entity = [NSEntityDescription insertNewObjectForEntityForName: @"Post" inManagedObjectContext:context];

        entity.inReply = dummy.in_reply;
        entity.body = dummy.body;
        entity.email = dummy.email;
        entity.from = dummy.from;
        entity.messageIdentifier = dummy.message_identifier;
        entity.references = dummy.references;
        entity.subject = dummy.subject;
        entity.dateCreated = dummy.date;
        entity.unread = [NSNumber numberWithInt:1];
...
    [self.context save:&error];
    if (error)
    {
        NSLog(@"error: %@", error);
    }

// IMPORTANT: CURRENTLY I AM CALLING THIS METHOD AGAIN HERE, WHICH 
// FETCHES ALL POSTS OUT OF CORE DATA.
// THIS IS SO UGLY AND NOT PERFORMANT. 
// THEN I INVOKE RELOADDATA ON THE TABLEVIEW TO RELOAD THE ENTIRE TABLE
// BUT THERE WAS JUST ONE INSERT SO A ENTIRE RELOAD WOULD NOT BE NECESSARY. 
    [self reloadNewsgroupsFromCoreData];
    [self.tableView reloadData];

// I HAVE TO DO THIS BECAUSE THE didChangeObject METHOD GETS NOT CALLED.
}

Does anyone have a hint or a suggestion what could be wrong?

Thanks and regards,
Chris

  • 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-06T13:13:52+00:00Added an answer on June 6, 2026 at 1:13 pm

    The problem is that you’re setting the controller delegate in viewDidLoad and then later allocating a new controller in reloadNewsgroupsFromCoreData. Your newly allocated controller doesn’t have the delegate set. Try setting the delegate directly in reloadNewsgroupsFromCoreData.

    You typically don’t want to allocate a new NSFetchedResultsController whenever something changes in your data. The entire point of using NSFetchedResultsController is to get delegate messages via NSFetchedResultsControllerDelegate when something changes. You only need to allocate a new NSFetchedResultsController if your fetch request changes. I suggest having another look at the Apple Docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Django but I seem to have nearly identical code working on
I have been building a game for a while (nearly done) - But the
I have an app that is nearly finished but encountered an annoying problem. In
So I have tried this out on multiple computers with multiple setups (servers/apps) and
I am learning RX (Reactive Extensions), and have found someone posted some code nearly
I know, there are several posts with nearly the same question, but all the
I have a nearly-boxplot like jitter-plot: dt <- rbind(se,cb,cb.se) qplot(ds, size, data=dt, geom="jitter", colour=root,
I'm nearly out of disk space because of a query that tried to update
I have been trying to figure out a weird issue with signed integers and
I have nearly finished a free spellchecker library for Windows Mobile, and there are

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.