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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:50:24+00:00 2026-05-23T01:50:24+00:00

I have a UITableView which uses a singleton object as a datasource. I have

  • 0

I have a UITableView which uses a singleton object as a datasource.

I have implemented the following methods to allow a user to delete the rows in the UITableView. But when I click the delete button the app crashes with a exception

Methods:

-(void)viewDidLoad
{

some initialization code-----

UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Delete"                                                        style:UIBarButtonItemStyleBordered                                                                 target:self                                                     action:@selector(toggleEdit:)];
       self.navigationItem.rightBarButtonItem = editButton;
       [editButton release];

}

-(IBAction)toggleEdit:(id)sender
{
    [self.myOrderTable setEditing:!self.myOrderTable.editing animated:YES];
    
    if(self.myOrderTable.editing)
        [self.navigationItem.rightBarButtonItem setTitle:@"Done"];
    else 
    {
     [self.navigationItem.rightBarButtonItem setTitle:@"Delete"];
    }

}

-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
    NSUInteger row = [indexPath row];
    
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                     withRowAnimation:UITableViewRowAnimationFade];
    
}

However I get the following exception when I try to click on the delete button:

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 1. 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).’

*** Call stack at first throw:
(
    0   CoreFoundation                      0x010305a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x01184313 objc_exception_throw + 44
    2   CoreFoundation                      0x00fe8ef8 
+[NSException raise:format:arguments:] + 136
    3   Foundation                          0x001153bb -
[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UIKit                               0x00398e8b -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8420
    5   UIKit                               0x00387cf8 -
[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 56
    6   Restaurant                          0x000117f9 -
[MyOrderViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 114
    7   UIKit                               0x00385037 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
    8   UIKit                               0x0031a4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    9   UIKit                               0x003aa799 -[UIControl sendAction:to:forEvent:] + 67
    10  UIKit                               0x003acc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    11  UIKit                               0x003ab7d8 -[UIControl touchesEnded:withEvent:] + 458
.............

..........
.............
)
terminate called after throwing an instance of 'NSException'

Where I can begin to solve this problem?

  • 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-23T01:50:25+00:00Added an answer on May 23, 2026 at 1:50 am

    “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).'”

    The error clearly says what’s wrong. I would examine your numberOfRowsInSection method. You need to account for the row being deleted. You can’t always return the same number of rows. If you’re deleting one row from the table, your numberOfRowsInSection needs to be returning it’s old return value minus 1.

    For example:

    Let’s say I use an array of strings to populate the tableview;

    My numberOfRowsInSection method would use

    return [array count];
    

    My cellForRowAtIndexPath method would use

    cell.textLabel.text = (NSString*)[array objectAtIndex:indexPath.row];
    

    When I delete a row (say row number 3) from the tableView, I would remove the object from the array as well:

    [array removeObjectAtIndex:3];
    

    This way when numberOfRowsInSection is called again, the array is one object smaller and numberOfRowsInSection returns one number less than before, which accounts for the deleted row.

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

Sidebar

Related Questions

I have an array of objects which populate a UITableView . When a user
In my iPhone app, I have a (non-grouped) UITableView which uses all the bells
I have very simple iPhone app, which uses just UIButtons , UIlabels , UITableView
I have set up a UITableView which has 3 sections in, with 3 rows
I have a UIViewController which uses the UITableViewDelegate and UITableViewDataSource. I have created UITableView
I have a need to display a UITableView containing a user's account credentials. For
I have an UITableView which includes a list of UITableViewCells. And I set the
i have a input tag which is non editable, but some times i need
Let say I have the following desire, to simplify the IConvertible's to allow me
I have a NSFetchedResultsController which displays data in a UITableView. I'm using the boiler

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.