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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:32:58+00:00 2026-05-31T06:32:58+00:00

I am learning editable sectioned UITableViews and I am having trouble figuring out why

  • 0

I am learning editable sectioned UITableViews and I am having trouble figuring out why my app crashes when deleting the last row in one of the sections. I’ve been looking around here and google and it looks to me that I have already done what most people say fixes this problem but no luck. I am stumped and appreciative of any help offered.

here is my method for deleting the table rows

myTableSections is an NSMutableArray holding NSDictionaries that represent the sections – “Possessions” is the key holding an array for the rows, and a key “Header” for the section header

PossessionStore is a singleton that holds all Possessions for the app in allPossessions array

The msg to divideSections is a method to sort allPossessions into NSDictionaries and store those into myTableSections

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{       ////If the table view is asking to commit the delete command
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        // Get the possesion from the row
        Possession *p = [[[myTableSections objectAtIndex:[indexPath section]] objectForKey:@"Possessions"] objectAtIndex:[indexPath row]];

        // delete it from the PossessionStore
        [[[PossessionStore defaultStore] allPossessions] removeObjectIdenticalTo:p];

        // Rebuild myTableViewSections to reflect the data change to the PossessionStore
        [self divideSections];

            // remove the row from the table view with an animation
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }
}

Oh yeah almost forgot this last part – debug info – at this point there are two rows in section 1 and one row in section 2. I then delete one row from section 1 and then the final row from section 1. according to the NSLog reports i put in and the error msg the section count is correct as it should be at that point but it doesn’t show the section ever being removed. If I understand it correctly??????????

2012-03-12 00:40:49.938 HomePwnr[53434:f803] commitEditingStyle:forRowAtIndexPath: called
2012-03-12 00:40:49.940 HomePwnr[53434:f803] myTableSections is holding - (
        {
        Header = "Cheap Stuff";
        Possessions =         (
            "Red Car (2U8F9): Worth $20, recorded on 2012-03-12 04:40:38 +0000",
            "Blue Gun (0X2Q7): Worth $14, recorded on 2012-03-12 04:40:40 +0000"
        );
    },
        {
        Header = "Expensive Stuff";
        Possessions =         (
            "Blue Mac (7R3K0): Worth $97, recorded on 2012-03-12 04:40:36 +0000"
        );
    }
)
2012-03-12 00:40:49.942 HomePwnr[53434:f803] divideSections called
2012-03-12 00:40:49.944 HomePwnr[53434:f803]  End of divideSections myTableSections is holding - (
        {
        Header = "Cheap Stuff";
        Possessions =         (
            "Red Car (2U8F9): Worth $20, recorded on 2012-03-12 04:40:38 +0000"
        );
    },
        {
        Header = "Expensive Stuff";
        Possessions =         (
            "Blue Mac (7R3K0): Worth $97, recorded on 2012-03-12 04:40:36 +0000"
        );
    }
)
2012-03-12 00:40:49.946 HomePwnr[53434:f803] returning number of sections: 2
2012-03-12 00:40:49.947 HomePwnr[53434:f803] returning number of sections: 2
2012-03-12 00:40:49.949 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 0
2012-03-12 00:40:49.951 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 0
2012-03-12 00:40:49.953 HomePwnr[53434:f803] tableView:numberOfRowsInSection called for section 0, returning - 1
2012-03-12 00:40:49.954 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 1
2012-03-12 00:40:49.956 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 1
2012-03-12 00:40:49.957 HomePwnr[53434:f803] tableView:numberOfRowsInSection called for section 1, returning - 1
2012-03-12 00:41:32.232 HomePwnr[53434:f803] commitEditingStyle:forRowAtIndexPath: called
2012-03-12 00:41:32.234 HomePwnr[53434:f803] myTableSections is holding - (
        {
        Header = "Cheap Stuff";
        Possessions =         (
            "Red Car (2U8F9): Worth $20, recorded on 2012-03-12 04:40:38 +0000"
        );
    },
        {
        Header = "Expensive Stuff";
        Possessions =         (
            "Blue Mac (7R3K0): Worth $97, recorded on 2012-03-12 04:40:36 +0000"
        );
    }
)
2012-03-12 00:41:32.236 HomePwnr[53434:f803] divideSections called
2012-03-12 00:41:32.238 HomePwnr[53434:f803]  End of divideSections myTableSections is holding - (
        {
        Header = "Expensive Stuff";
        Possessions =         (
            "Blue Mac (7R3K0): Worth $97, recorded on 2012-03-12 04:40:36 +0000"
        );
    }
)
2012-03-12 00:41:32.239 HomePwnr[53434:f803] returning number of sections: 1
2012-03-12 00:41:32.241 HomePwnr[53434:f803] returning number of sections: 1
2012-03-12 00:41:32.242 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 0
2012-03-12 00:41:32.244 HomePwnr[53434:f803] tableView:titleForHeaderInSectionCalled - section = 0
2012-03-12 00:41:32.246 HomePwnr[53434:f803] tableView:numberOfRowsInSection called for section 0, returning - 1
2012-03-12 00:41:32.248 HomePwnr[53434:f803] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1021
2012-03-12 00:41:32.250 HomePwnr[53434:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
*** First throw call stack:
(0x13cc022 0x155dcd6 0x1374a48 0x9ad2cb 0x9b103 0xa66d2 0xa674d 0x3409 0xb26e2 0x208e6b 0x13cde99 0x1914e 0x190e6 0xbfade 0xbffa7 0xbf266 0x3e3c0 0x3e5e6 0x24dc4 0x18634 0x12b6ef5 0x13a0195 0x1304ff2 0x13038da 0x1302d84 0x1302c9b 0x12b57d8 0x12b588a 0x16626 0x20dc 0x2085)
terminate called throwing an exception(lldb) 
  • 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-31T06:33:00+00:00Added an answer on May 31, 2026 at 6:33 am

    Apologies to all pointing me in the right direction last night. I was too tired and frustrated to get it I had been banging my head against this too long. Here was my final solution that fixed it.

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {       ////If the table view is asking to commit the delete command
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            BOOL lastRow = FALSE;
            if ([tableView numberOfRowsInSection:[indexPath section]] == 1 ) {
                lastRow = TRUE;
            }       
            // Get the possesion from the row
            Possession *p = [[[myTableSections objectAtIndex:[indexPath section]] objectForKey:@"Possessions"] objectAtIndex:[indexPath row]];
    
            // delete it from the PossessionStore
            [[[PossessionStore defaultStore] allPossessions] removeObjectIdenticalTo:p];
    
            // Rebuild myTableViewSections to reflect the data change to the PossessionStore
            [self divideSections];
    
                // remove the row or section if last row from the table view with an animation
            if (lastRow) {
                // NSLog(@"Should be deleting section");
                [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:YES];
            } else {
                // NSLog(@"Should be deleting row");
                [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

learning Jquery and integrating with PHP - getting there, but have one last challenge
Learning how to do a master page in asp.net. Trying to figure out how
Learning from my last question , most member names seem to get included in
Learning about Explicit Cursors and trying to create my frst one.: SET SERVEROUTPUT ON
Learning C# here. I have a monthly process form whereby one can select to
Learning a lot in my few years of programming that the best projects are
Learning Scala currently and needed to invert a Map to do some inverted value->key
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
Learning about notifyAll made me question something about notify: in a typical situation we
When learning new languages such as C++ from PHP, does reading other language snippets

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.