Yes, so many questions are asked about stack overflow on a similar question title. I read everything, but I never saw my problem equivalent to them. Now my problem is that if I update the section of table 0 with 3 rows when I click on the heading in section 0 and then click on the same heading again to remove all 3 rows from section 0, this works fine with me. But if I open (update section 0 with three lines), and then I click on another section of the header (another section that I want to open after the 0th section), my application crashed. I want to say what I want, if I click on another section, then my other section should be open, and the previous open section should be closed. see my code for insert and delete sections and lines,
-(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, Approval error at - [UITableView _endCellAnimationsWithContext:], / SourceCache / UIKit_Sim / UIKit-2372 / UITableView.m: 1070 Cause: Invalid update: invalid number of lines in section 0. Number of lines contained in existing section after: "Invalid update: Invalid number of lines in section 0. The number of lines contained in an existing section after update (0) must be equal to the number of lines contained in this section before updating (3) plus or minus the number of lines inserted or deleted from this section (vst claimed 0, 1 removed) plus or minus the number of rows displaced in or out of this section (0 moved, shifted 0).
Just suppose my 2 sections contain 3 to 3 lines, then the file will work. But if 2 sections contain 3 - 2 lines, then it fails. I want to switch two sections by clicking on the update of the section title with an inconsistent number of lines in these sections.
Than
ios iphone uitableview
Tirth
source share