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

The Archive Base Latest Questions

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

My first question on stackoverflow (<< n00b). I’m working on my first project involving

  • 0

My first question on stackoverflow (<< n00b). I’m working on my first project involving UITableViews and plists, and I’m having an issue.

The property list consists of a dictionary holding 3 sections/categories (each an array) and a number of entries in each of these.

The lists load just fine. The problem doesn’t occur until I try making it possible to delete individual entries from the list.

Here’s my code:

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

if (editingStyle == UITableViewCellEditingStyleDelete) {

    //make array of the objects and remove the selected object from that array.
    NSMutableArray *delArray = [faves objectForKey:[entries objectAtIndex:indexPath.section]];
    [delArray removeObjectAtIndex:indexPath.row];

    //set entries to the value of the array, now sans the removed object.
    self.entries = delArray;
    [delArray release];

    //write the updated entries to the plist file.
    NSArray *rootPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [rootPath objectAtIndex:0];
    NSString *plistFile = [docsPath stringByAppendingPathComponent:@"Data.plist"];
    [faves writeToFile:plistFile atomically:YES];

    //update the actual tableview. This is where things go awry.
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; //ends up trying to load the sections instead of the entries = wrong number of list items returned = crash!

    //[tableView reloadData]; //works if I only use this line, but the list updates wrong, showing each entry as a section header.
    }
}

The entry IS deleted from the plist correctly, but the table fails to update right and causes the app to crash. I’ve included the error code below.

2011-09-23 18:40:19.732 MyApp[10314:b303] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:974
2011-09-23 18:40:19.734 MyApp[10314:b303] *** 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 (5) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

The first number (5) is consistent with how many records are supposed to be left in the affected category, but the second number (3) refers to the number of categories. Like I said above, the entry is deleted from the plist – just not the table.

  • 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-26T01:07:51+00:00Added an answer on May 26, 2026 at 1:07 am

    Considering the following two methods:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return [entries count];
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
       NSString *key = [entries objectAtIndex:section];
       NSArray *sectionNames = [faves objectForKey:key];
       return [sectionNames count];
    } 
    

    It appears that “entries” is an NSArray of key names (NSString) and that “faves” is an NSDictionary of section content (NSArrays).

    The problem is that you are replacing your array of key names (self.entries) with a single section’s content array. I’ve expanded your code to make the logic error a little more obvious:

    // query for section key name by section index
    NSString       * keyName        = [entries objectAtIndex:indexPath.section];
    
    // retrieve array of a section's datasource (array of rows)
    NSMutableArray * delArray = [faves objectForKey:keyName];
    
    // remove row from a section's datasource
    [delArray removeObjectAtIndex:indexPath.row];
    
    // ERROR: assign an array of rows to array used for section names
    self.entries = delArray;
    

    Changing your code to the following should remove the assertions generated by the UITableView:

    (void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
    
    //make array of the objects and remove the selected object from that array.
    NSMutableArray *delArray = [faves objectForKey:[entries objectAtIndex:indexPath.section]];
    [delArray removeObjectAtIndex:indexPath.row];
    
    //write the updated entries to the plist file.
    NSArray *rootPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [rootPath objectAtIndex:0];
    NSString *plistFile = [docsPath stringByAppendingPathComponent:@"Data.plist"];
    [faves writeToFile:plistFile atomically:YES];
    
    //update the actual tableview. This is where things go awry.
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; //ends up trying to load the sections instead of the entries = wrong number of list items returned = crash!
    
    //[tableView reloadData]; //works if I only use this line, but the list updates wrong, showing each entry as a section header.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First question on Stackoverflow. After using JOIN to map a property I try to
This is my first stackoverflow question, so try to be nice. ;-D My issue
Longtime reader of stackoverflow but first question. I'm working with Wordpress (specifically thesis theme)
First question on Stackoverflow (.Net 2.0): So I am trying to return an XML
this is my first question to stackoverflow so here it goes... I use cruise
This is my first question on stackoverflow. I just wonder why my getJSON code
This is my first StackOverflow question so be nice! :-) I recently came across
Greetings to all! This is my first question here on stackoverflow. I have a
First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried
First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript

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.