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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:02:55+00:00 2026-06-19T04:02:55+00:00

Yes there are so many question ask on stack overflow on similar title of

  • 0

Yes there are so many question ask on stack overflow on similar title of question. I read those all but i never see my problem equivalent to them.
Now my problem is if when i update table section 0 having 3 rows on click of headerview on section 0 and then again i click on same header for delete all 3 rows from the section 0, this work fine with me. But if i open(update section 0 with 3 rows) and then i click on another header section (another section i want to open then after 0th section) my application crashed. I mean i want to if i click other section then my other section should have open and previous open section should have to close. see my code for insertion and deletion sections and rows,

 -(void)sectionHeaderView:(TableHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section{

self.sectionOpen = YES;
//Create an array containing data of rows and section which to be inserted in tableView.
NSMutableArray *dataInsertArray = [NSMutableArray arrayWithArray:[self.tableDataSourceDictionary objectForKey: [self.sortedKeys objectAtIndex:section]]];
NSInteger countOfRowsToInsert = [dataInsertArray count];

NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
    [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
[self.tableContents setObject:dataInsertArray forKey:[self.sortedKeys objectAtIndex:section]];

//Create an array containing data of rows and section which to be delete from tableView.
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
NSInteger previousOpenSectionIndex = self.openSectionIndex;
if (previousOpenSectionIndex != NSNotFound )  {

    self.sectionOpen = NO;
    [previousTableHeader toggleOpenWithUserAction:NO];
    NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
    for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
        [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
    }

    [self.tableContents removeObjectForKey:[self.sortedKeys objectAtIndex:previousOpenSectionIndex]];
}

// Apply the updates.
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

self.openSectionIndex = section;
self.previousTableHeader = sectionHeaderView;
}

And my data-source methods,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
NSInteger numberOfSection = [self.sortedKeys count];
return numberOfSection;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *listData =[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]];
NSInteger numberOfRows = [listData count];
return numberOfRows;
}

My crash report,
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070
2013-02-18 11:44:49.343 ManageId[1029:c07] Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (3), 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).’

Simply Suppose my 2 sections has contain 3 – 3 rows then it will worked file But if 2 sections contain 3 – 2 rows then it crash. I want to toggle two sections click on updating header of section with inconsistent numbers of rows in those sections.

Than

  • 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-19T04:02:56+00:00Added an answer on June 19, 2026 at 4:02 am

    I found that please replace that code in your code with that code. you have to delete data with old one index not with current one….
    the commented line was yours please check that…

    if (previousOpenSectionIndex != NSNotFound){
     self.sectionOpen = NO; 
     [previousTableHeader toggleOpenWithUserAction:NO];
    
    //NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
    NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] count];   
    
    for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
    [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
     }
    
    [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:previousOpenSectionIndex]] removeAllObjects];  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes I know, this question has been asked MANY times but after reading all
As far as i know there are many other questions similar to title, but
First of all, YES, I know there are many highlight jquery plugins out there,
I know this is an often asked question, but as there are so many
Ok I know there are many possible duplicate questions but none answers my question.
There are many questions related to Stackless Python. But none answering this my question,
I know there are many other posts on here with similar questions, but I
Yes, this might sound like a newbie question but there's a TWIST! ( And
I've Googled this and read many posts, but there are so many different answers
I hate to ask such a newbie and vague question, but I imagine there

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.