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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:26:41+00:00 2026-05-26T22:26:41+00:00

I have a parent class that handles all the UITableview persistent data management and

  • 0

I have a parent class that handles all the UITableview persistent data management and UITableView row managemetn. I’ve copied most of the code from a new XCode4 project with persistent data for a UITableview. Now I’m trying to delete a tablerow in a child class, and none of the delegate methods get called when a row is deleted, causing my tableview to be left in an inconsistent state.

Am I assigning the delegate correctly? Who’s the delegate of the NSFetechedResultsController in this case? Do I need to explicitly make my child class a NSFetchedResultsControllerDelegate?

Here’s how I retrieve the NSFetchedResultsController, note how it assigns self as the delegate.

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

    /*
     Set up the fetched results controller.
    */
    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:self.managedObjectContext];

    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:fetchBatchSize];

    // Edit the sort key as appropriate.
//    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"startMinute" ascending:YES];
    NSArray *sortDescriptors;
    if(sortDescriptor2!=nil)
    {
     sortDescriptors= [[NSArray alloc] initWithObjects:sortDescriptor,sortDescriptor2, nil];
    }else
    {
     sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    }
    [fetchRequest setSortDescriptors:sortDescriptors];

    if(filterPredicate != nil)
    {
        [fetchRequest setPredicate:filterPredicate];
    }

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;



    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&error])
        {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
//      abort();
    }

    return __fetchedResultsController;
}  

When it’s time to delete table rows, none of the delegate methods get invoked, even thought the table row is really deleted. To debug the issue, I added the following 2 assertions. The second assertion fails.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    id delegate = self.fetchedResultsController.delegate;


    NSAssert(delegate!=nil,@"Tableview is not delegate of fetched results controller!");

//this assertion fails
    NSAssert([((UITableViewController*)self) isEqual:delegate],@"Tableview is not delegate of fetched results controller!");

    if (editingStyle == UITableViewCellEditingStyleDelete)
    {


        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

        [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

        // Save the context.
        NSError *error = nil;
        if (![context save:&error])
        {
            /*
             Replace this implementation with code to handle the error appropriately.

             abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
             */
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
//            abort();
        }
    }   
}

Thank you !

  • 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-26T22:26:42+00:00Added an answer on May 26, 2026 at 10:26 pm

    The code setting up the NSFetchedResultsController looks correct. It’s delegate set to self means it’s delegate is the object you are creating it in. This looks like the same object that is the delegate for the tableView. It also looks like you correctly deleting the object and saving the context.

    What you don’t show and is likely the cause of the crash is your handling of the NSFetchedResultsController delegate methods. At a minimum, you need to add the following:

    - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
    {
        [self.tableView reloadData];
    }
    

    This will force the table to reload whenever the fetchedResultsController updates itself when it detects changes in its managedObjectContext.

    If this is not your issue then you need to post some more code showing how you have your classes configured and how you are handling the fetchedResultsController delegate methods.

    EDIT: fixed incorrect signature om controllerDidChangeContent:

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

Sidebar

Related Questions

I have a parent and child class that both need to implement IDisposable .
I have a private method def __pickSide(self): in a parent class that I would
In Django, when you have a parent class and multiple child classes that inherit
I have a parent class which contains a child object. I am using set
I have a parent class and child class (inherited from parent). In the child
I have a MustInherit Parent class with two Child classes which Inherit from the
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
I have a Model with a Foreign Key of Parent class Item(models.Model): parent =
I have a base class Parent like this: using System; using System.Collections.Generic; using System.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.