Note that there are some explanatory texts on larger screens.

plurals
  1. POSections Expansion in UITableview - When pushed again to the view the expanded section gets disappear
    text
    copied!<p>Trying to expand the sections in UITableview. Everything is working fine but if the expanded section is not closed and the view is popup and then push to that view again where tableview is, the section expanded last time gets disappear and if any section in tableview selected the app crashes. I checked through breakpoint the issue is next time it starts with section1 not from section0. Why this is happening i am not getting. Below is the code i am using.</p> <pre><code>-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { return [self.arrList count]; } -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(section == 0) { if(indexSectionOne) { return [self.arrProductsList count]; } else { return 1; } } if(section == 1) { if(indexSectionTwo) { return [self.arrServicesList count]; } else { return 1; } } else return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"CellIdentifier"; AboutCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(cell==nil) { cell = [[AboutCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; } /* if((indexPath.section == 0)||(indexPath.section == 1)) { if(indexPath.row == 0) { cell.imgDwnView.image = [UIImage imageNamed:@"down_arrow_about_iPhone.png"]; } } */ NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); if(indexPath.section == 0) { if(indexPath.row == 0) { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.imgDwnView.image = [UIImage imageNamed:@"down_arrow_about_iPhone.png"]; } //if(indexPath.row != 0) else { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.imgView.image = [UIImage imageNamed:[self.arrImages objectAtIndex:0]]; cell.lblView.text = [[self.arrProductsList objectAtIndex:indexPath.row-1] valueForKey:@"ProductName"]; cell.txtView.text = [[self.arrProductsList objectAtIndex:indexPath.row-1] valueForKey:@"ProductDescription"]; } } if(indexPath.section == 1) { if(indexPath.row == 0) { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.imgDwnView.image = [UIImage imageNamed:@"down_arrow_about_iPhone.png"]; } //if(indexPath.row != 0) else { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.imgView.image = [UIImage imageNamed:[self.arrImages objectAtIndex:1]]; cell.lblView.text = [[self.arrServicesList objectAtIndex:indexPath.row-1] valueForKey:@"LinkTitle"]; cell.txtView.text = [[self.arrServicesList objectAtIndex:indexPath.row-1] valueForKey:@"ProductDescription"]; } } if(indexPath.row == 0) { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_background_about_iPhone.png"]]; cell.lblView.text = [self.arrList objectAtIndex:indexPath.section]; cell.imgView.image = [UIImage imageNamed:[self.arrImages objectAtIndex:indexPath.section]]; cell.lblView.font = [UIFont fontWithName:@"NeoSansCyr-Regular" size:15.0f]; cell.lblView.textColor = [UIColor colorWithRed:144.0/255.0 green:8.0/255.0 blue:8.0/255.0 alpha:1.0]; } else { NSLog(@"row:%d section:%d", indexPath.row, indexPath.section); cell.lblView.frame = CGRectMake(60, 15, 150, 25); cell.imgView.frame = CGRectMake(13, 15, 30, 30); cell.txtView.frame = CGRectMake(60, 42, 180, 50); cell.imgDwnView.frame = CGRectMake(270, 18, 19, 10); cell.imgDwnView.image = [UIImage imageNamed:@"down_arrow_about_iPhone.png"]; //cell.lblView.text = @"Labels"; // cell.imgView.image = [UIImage imageNamed:@"Icon-small.jpg"]; // cell.txtView.text = @"Description"; cell.contentView.backgroundColor = [UIColor whiteColor]; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.section == 0) { indexSectionOne = !indexSectionOne; if(indexSectionOne) { } else { } [self.tblAboutView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; } if(indexPath.section == 1) { indexSectionTwo = !indexSectionTwo; if(indexSectionTwo) { } else { } [self.tblAboutView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; } if(indexPath.section == 2) { MapViewController *mapView = [[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil]; mapView.strTitle = @"Branches/ATM"; [self.navigationController pushViewController:mapView animated:YES]; } if(indexPath.section == 3) { MapViewController *mapView = [[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil]; mapView.strTitle = @"Sadara Centre"; [self.navigationController pushViewController:mapView animated:YES]; } if(indexPath.section == 4) { NSString *strRoadAsstNo = [dictData valueForKey:@"RoadSideAssistanceNo"]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strRoadAsstNo]]; } if(indexPath.section == 5) { NSString *strContactNo = [dictData valueForKey:@"ContactCenterNo"]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strContactNo]]; } } Update: Error: 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 (33) must be equal to the number of rows contained in that section before the update (0), 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).' </code></pre> <p>Thanks in advance. Please guide for above where i am doing wrong.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload