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

  • Home
  • SEARCH
  • 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 6001581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:51:18+00:00 2026-05-23T00:51:18+00:00

I have 2 views. One display Shopping Lists from Core Data using NSFetchResultsController. The

  • 0

I have 2 views. One display Shopping Lists from Core Data using NSFetchResultsController. The second one displays items on this lists using simple NSFetchRequests. Both views contain UITableView.

When I start app I create NSFetchResultsController (subclassed by ActiveFetchResults)

-(id)initActiveFetch{

      NSFetchRequest *request = [[NSFetchRequest alloc] init];

      NSEntityDescription *entity = [NSEntityDescription entityForName:@"Lista" inManagedObjectContext:[CoreDataHandler context]];

      [request setEntity:entity];

      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"archive == 0 AND deleted == NO"];

      [request setPredicate:predicate];

      NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:NO];

      NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

      [request setSortDescriptors:sortDescriptors];

      [sortDescriptors release];

      [sortDescriptor release];

      if (self=[[ActiveFetchResults alloc] 

                    initWithFetchRequest:request 

                    managedObjectContext:[CoreDataHandler context] 

                    sectionNameKeyPath:nil 

                    cacheName:nil]) 

      {

            self.delegate = self;

      }

      [request release];

      return self;

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [[self sections] count];

} 

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {

    id <NSFetchedResultsSectionInfo> sectionInfo = [[self sections] objectAtIndex:section];

    return [sectionInfo numberOfObjects];

} 

- (NSInteger)numberOfRowsInSection{

    id <NSFetchedResultsSectionInfo> sectionInfo = [[self sections] objectAtIndex:0];

    return [sectionInfo numberOfObjects];

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

      ActiveListsCell* cell;

      cell = (ActiveListsCell*)[tableView dequeueReusableCellWithIdentifier:@"ActiveLists"]; 

      if (cell == nil) {

            cell = [[[ActiveListsCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"ActiveLists"] autorelease];

      } 

      NSManagedObject *managedObject = [self objectAtIndexPath:indexPath];

      [cell setLista: (Lista*)managedObject];

      NSLog(@"%@, %@, %d ",managedObject, [managedObject name], [[managedObject items] count]);

      cell.activeListsDelegate = self;

      [cell.roundedView setAlpha:1.0];

      cell.button.alpha = 1.0; 

      cell.counter.alpha = 1.0;

      return cell;

} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 

    id <NSFetchedResultsSectionInfo> sectionInfo = [[self sections] objectAtIndex:section];

    return [sectionInfo name];

} 

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    return [self sectionIndexTitles];

} 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

    return [self sectionForSectionIndexTitle:title atIndex:index];

} 

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {

    [self.tableView beginUpdates];

} 


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo

               atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 

    switch(type) {

        case NSFetchedResultsChangeInsert:

            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]

                                      withRowAnimation:UITableViewRowAnimationFade];

            break; 

        case NSFetchedResultsChangeDelete:

            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]

                                      withRowAnimation:UITableViewRowAnimationFade];

            break;

    }

} 

//-(BOOL)performFetch:(NSError **)error{

// ActiveFetchResults* ss = self;

// self = [self initActiveFetch];

// 

// self.listView = ss.listView;

// self.listView.activeFetch = self;

// [self.listView.tableView setDelegate:self];

// [self.listView.tableView setDataSource:self];

// 

// [ss release];

// return [super performFetch:error];

//} 

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject

         atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type

        newIndexPath:(NSIndexPath *)newIndexPath { 

    UITableView *tableView = self.tableView; 

    switch(type) { 

        case NSFetchedResultsChangeInsert:

            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]

                                           withRowAnimation:UITableViewRowAnimationFade];

            break; 

        case NSFetchedResultsChangeDelete:

            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]

                                           withRowAnimation:UITableViewRowAnimationFade];

            break; 

        case NSFetchedResultsChangeUpdate:

                  if ([anObject isKindOfClass:[Lista class]]) {

                        Lista* lista = (Lista*)anObject;

                        if ([[lista deleted] boolValue]) {

                              [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]

                                                       withRowAnimation:UITableViewRowAnimationLeft];

                        }

                  }

                  else

                        [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;

    }

} 


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {

    [self.tableView endUpdates];

} 

-(void)configureCell:(UITableViewCell*)cell atIndexPath:(NSIndexPath*)indexPath{

      ActiveListsCell* activeCell = (ActiveListsCell*)cell;

      NSManagedObject *managedObject = [self objectAtIndexPath:indexPath];

      [activeCell setLista: (Lista*)managedObject];

}

When I go to second View and add new Item for selected list by adding Item object to Core data and I return to List View it still shows old number of objects. And the items property of list which should show me all Items objects for this list is an NSarray object with items count not including new added objects. But second View shows me all items with those new added too.

In few words it looks like by using NSFetchResultsController I have all object frozen from the first fetch and not responding to changes despite using “performFetch:” function. While using simple NSFetchRequest in second View everything works fine.

Can someone tell me why NSFetchResultsController objects stay frozen and do not change while core data records change?

  • 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-05-23T00:51:18+00:00Added an answer on May 23, 2026 at 12:51 am

    Possible issues:

    1. Did you save NSManagedObjectContext after you updated or added objects?

    2. Try adding this case

      case NSFetchedResultsChangeUpdate:
      [self.tableView reloadData];
      break;

    in your - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type method

    1. try reloading data of tableview every time after you perform fetch:

      [self.tableView reloadData];

    2. If it still doesn’t work, review the core data recipes sample code of Apple: http://developer.apple.com/library/ios/#samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html

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

Sidebar

Related Questions

I have two views, one view takes the whole screen, the second view covers
I have this in one of my haml views: -form_for :news_item_comment, :url=>{:id => comment.id,
I have something like this in one of my views <li <?php $isCurrent ?
I have a multiview application using a tab bar to switch views. One is
I have two views, first one is with calendar and the second one is
I have to display three text views above a map in one of my
I have 2 views. The first one is the main UIViewController and the second
I have some views and I want to display them one by one .
I have two views within one .xib (one view for landscape, another for portrait).
I have two views that I would like to combine into one. The first

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.