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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:33:42+00:00 2026-05-28T07:33:42+00:00

I’ve added to my UITableView the following method to provide the user with the

  • 0

I’ve added to my UITableView the following method to provide the user with the option to delete a line:

(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

I have copied this method from the XCode template with the option

Use CoreData for Storage

Once the user pushes the addButton in the UITableView a new UIView is opened where he should enter the information for a new entity.

Then the user touches the saveButton in the UIView. The information is read and stored in the context. The UIView is closed and the user will get back to UITableView.

The new entry now appears in a new row. If the user now realizes he has made ​​a mistake and wants to delete this row immediately (wipe from left to right and then touch “Delete”) the row remains and nothing else happens. The following error is thrown to me:

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). 
with userInfo (null)

But deleting the row works if I exit the app before the deleting happens. (and re-viewed, and then delete)

In controllerDidChangecontent only [self.tableView endUpdate] is called.

My method looks like this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
        [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

        //NSLog(@"DATE: %@", [[UIApplication sharedApplication] scheduledLocalNotifications]);


        for (UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {

            NSLog(@"N: %@", notification.fireDate);
            NSLog(@"O: %@", [[self.fetchedResultsController objectAtIndexPath:indexPath] valueForKey:@"zeit"]);

            if (notification.fireDate == [[self.fetchedResultsController objectAtIndexPath:indexPath] valueForKey:@"zeit"]) {
                [[UIApplication sharedApplication] cancelLocalNotification:notification];
                NSLog(@"GELÖSCHT!");
            }
        }

        // 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();
        }
    }   
}

I think the row was added but not commited. And then it will attempt to delete a row that it does not know about. Do I understand this correctly?
But I do not know exactly where to fix the error.
What can I do? Does anybody know?

  • 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-28T07:33:42+00:00Added an answer on May 28, 2026 at 7:33 am

    Look at the error message: you also have to delete the row from the table view.

    If you are using an NSFetchedResultsController, you can do it like this:

    // in controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
    case NSFetchedResultsChangeDelete:
       [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                        withRowAnimation:UITableViewRowAnimationFade];
    break;
    

    Also notice that your fetchedResultsController has to be informed that it should re-fetch the a new result set – otherwise tableView:numberOfRowsInSection will return the old value. So you need to insert:

    self.fetchedResultsController = nil;
    

    It will recreate itself lazily with the correct sections and rows.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.