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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:09:26+00:00 2026-06-09T15:09:26+00:00

i use NSFetchedResultsController to populate tableview and every thing is ok(adding, deletng..).. But whenever

  • 0

i use NSFetchedResultsController to populate tableview and every thing is ok(adding, deletng..).. But whenever i try to remove last row from tableview(when there is only one row in tablview) the app crashes with the log below:

 *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037
2012-08-03 16:32:39.667 MackaWithCoreData[793:15503] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  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 (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

As far as i see, after deleting the object when the delegate methods try to reload the tableview since the fetchedResultsController is null it causes a crash.. How to handle this issue? Thanks in advance

EDIT Implementation of controller controllerDidChangeContent:... method is below

 - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{

    switch(type)
    {

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

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            XLog(@"the row removed from tv");

            break;

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

        case NSFetchedResultsChangeMove:
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            XLog(@" object deleted from fetchedresultscontroller");

            [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}
  • 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-09T15:09:28+00:00Added an answer on June 9, 2026 at 3:09 pm

    After a few days i decided a different logic to solve this issue. I firstly control the count of fetchedObjects on fetchedResultsController, if the count is greater than 1 i call deletion & saving delegates on database, but if the count is equal to 1, just push to a different viewController. On that vc too, i’ll disable navigation controller back to this view controller untill a new message comes. And when a new message comes, i will firstly delete the object on entity and than add the message..

    Here is some pseudo code & algorithm:

         if ([[self.fetchedResultsController fetchedObjects]count] >1) {
             callDeletionDelegateForDatabase;
          }else{
           declare a viewController object;
           pushToThatVC;
          }
    

    // on the class of target vc

    hide_back_navigation_back_to_theViewControllerYouCameFrom;
         //when a new message comes from web service
         reset Entitiy(the property we need its value)
         show_navigation_Controller_To_theViewControllerOfMessages...
    

    I posted this stupidly coded pseudo to help others who faces the same situation, if anyone knows a better approach, please write down.
    Below is my code:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
         if (editingStyle == UITableViewCellEditingStyleDelete) { 
             if ([[self.fetchedResultsController fetchedObjects]count] >1) {
    
            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. 
                 */ 
                NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
                abort(); 
                } 
             }else {
                 BNT_DetailViewController *vc=[BNT_DetailViewController new];
                 [self.navigationController pushViewController:vc animated:YES];
    
                 XLog(@"You Cant delete this");
             }
         } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use nsfetchedresultscontroller to maintain entity Product. But i set a predicate forUser==%@, currentUser
How could I use the NSFetchedResultsController with translated sort key and sectionKeyPath? Problem: I
Is it wrong to use an NSFetchedResultsController purely for data management, i.e., without using
I'm developing an iPhone app where I use a NSFetchedResultsController in the main table
I've got a table using NSFetchedResultsController to automatically populate and update the table view.
My app use CoreData. It has a UISegmentedControl and a tableview. The UISegmentedControl is
In a UITableViewController , I use an NSFetchedResultsController for my data. Everything works fine,
The documentation for the NSFetchedResultsController states that it is intended for use to 'efficiently
I am familiar with the common and basic use of a NSFetchedResultsController managing the
I would like to know if I can do this VIEW 1: use NSFetchedResultsController

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.