title: Adding dynamic sub-rows by selecting tableview row in tableview iPhone errors?
body: <p>I want to add row dynamically. I have tableview list of building names. If some one choose building(didSelectRowAtIndexPath) then respective floors of building should get added dynamically as subrow. Its like maximizing and minimizing the subrow on respective building list selection. How do I do this. Thanks in advance...</p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  // There is only one section.
  if (tableView == indoortable || tableView == indoortable_iPad)
  {
      return 1;
  }
  }
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    {
  // Return the number of time zone names.
  if (tableView == indoortable || tableView == indoortable_iPad)
  {
      return [indoorZones count];
  
  }
  
  }
  </code></pre>
  
  <p>cellForRowAtIndexPath method:</p>
  
  <pre><code>  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  if (tableView == indoortable || tableView == indoortable_iPad)
  {
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) 
      {
          cell = [[[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
  
          cell.selectionStyle = UITableViewCellSelectionStyleGray;             //cell bg
          cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      }       
      // Set up the cell.
      //cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
  
      cell.textLabel.text =[indoorZones objectAtIndex: indexPath.row];
      //[cell setIndentationLevel:[[self.indoorZones objectAtIndex:indexPath.row] intValue]];
      return cell;
  }
  }
  </code></pre>
  
  <p>didSlectRowAtIndexPath method:</p>
  
  <pre><code> - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath 
   {
  zonesFloor = [[NSMutableArray alloc]init];
  zonesFloorA = [[NSArray alloc] initWithObjects:@"Gr fl",@"1st fl",@"2nd fl",nil];
  
  [zonesFloor addObject:zonesFloorA]; 
  if (tableView == indoortable )
  {
  
      NSUInteger i=indexPath.row+1;
      for (NSArray *count in self.indoorZones)  //app is crashing here giving  error.......Collection &lt;__NSArrayM: 0x4b1d550&gt; was mutated while being enumerated.
   {
  
          [zonesFloor addObject:[NSIndexPath indexPathForRow:i inSection:0]];
          [self.indoorZones insertObject:zonesFloor atIndex:i++];
  
  
      }
  
      [[self indoortable] beginUpdates];
      [[self indoortable] insertRowsAtIndexPaths:(NSArray *)zonesFloor  withRowAnimation:UITableViewRowAnimationNone];
      [[self indoortable] endUpdates];
  
      }
  
  
  if (tableView == indoortable_iPad )
  {
  
      //some logic
  }
  
  [tableView deselectRowAtIndexPath:selectedIndexPath animated:NO];
  }
  </code></pre>
  
  <p>It Gives following error [__NSArrayI compare:]: Or [NSIndexPath _fastCStringContents:]:  unrecognized selector sent to instance.  I tried many ways but may be I am lacking somewhere. Please suggest. thanks in advance. </p>