I am creating one table based application using TQMultistageTableView
library to expand sections. My requirement is if the user will tap on table sections then section background color should change to blue color, rest section background color should be white color if not selected/expanded. For this, I have created an array to save the section index and then I'm reloading this section.
Very first time (when my array is nil), its working fine. But the problem is when there is one section index saved in my array (as any one section is expanded/selected) and then I am trying to expand other section with reloading the second section, that time it's crashing with below error :
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:1368
*** 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 (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, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Here is my code :
//header open method
- (void)mTableView:(TQMultistageTableView *)mTableView1 willOpenHeaderAtSection:(NSInteger)section
{
NSLog(@"Open Header ----%ld",section);
NSDictionary *selectedSection = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%ld", (long)section] ,@"section" ,nil];
for(int i=0;i<[ selectedArrayForSectionPlus count];i++)
{
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[selectedArrayForSectionPlus removeObjectAtIndex:i];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
return;
}
}
[selectedArrayForSectionPlus addObject:selectedSection];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];//here it is crashing
}
//header close method
- (void)mTableView:(TQMultistageTableView *)mTableView willCloseHeaderAtSection:(NSInteger)section
{
NSLog(@"Close Header ---%ld",section);
for(int i=0;i<[ selectedArrayForSectionPlus count];i++)
{
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[selectedArrayForSectionPlus removeObjectAtIndex:i];
[self.mTableView.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
return;
}
}
}
//viewForHeaderInSection method
- (UIView *)mTableView:(TQMultistageTableView *)mTableView viewForHeaderInSection:(NSInteger)section;
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mTableView.frame.size.width, 80)];
for (int i = 0; i<selectedArrayForSectionPlus.count; i++) {
if([[[selectedArrayForSectionPlus objectAtIndex:i] objectForKey:@"section"] isEqualToString:[NSString stringWithFormat:@"%ld", (long)section]])
{
[view setBackgroundColor:[UIColor colorWithRed:0/255.0 green:150/255.0 blue:214/255.0 alpha:1.0]];
}
else
{
[view setBackgroundColor:[UIColor whiteColor]];
}
}
return view;
}
Does anyone have any idea how to reload the section?
Thanks for any pointers!