title: How to populate, Expandable TableView with two NSMutableArray using objective-c
body: <p>I am using an <a href="https://github.com/wannabegeek/ExpandableTableView" rel="nofollow">Expandable UITableview</a> created by Tom Fewster. I want to tweak the example using two <code>NSMutableArray</code>s, which is a scenario whereby if someone wants to populate an expandable/collapse treeview table from webservice json data would want to achieve. So since in his example the  <code>GroupCell</code> does not have an array of, I am wondering how can I do it? Please bear in mind that my Objective-C is still rusty hence, I'm asking this question.</p>
  
  <p>With my attempt is only displaying the first ObjectAtIndex:indexPath:0 for the group.</p>
  
  <p>I want to be able to populate the table and get output like this;</p>
  
  <ul>
  <li>Group A
  <ul>
  <li>Row 1a</li>
  <li>Row 2a</li>
  <li>Row 3a</li>
  </ul></li>
  <li>Group B
  <ul>
  <li>Row 1b</li>
  <li>Row 2b</li>
  </ul></li>
  <li>Group C
  <ul>
  <li>Row 1c</li>
  <li>Row 2c </li>
  <li>Row 3c
  and so on.</li>
  </ul></li>
  </ul>
  
  <p>You may use JSON data as well to explain your answer if you understand it better that way.</p>
  
  <p>Here i want to populate the table with JSON data so the GroupCell show class_name and rowCell show subject_name. This is the console of what I am parsing from the JSON web-service;</p>
  
  <pre><code>(
      {
      "class_id" = 70;
      "class_name" = Kano;
      subject =         (
  
              "subject_id" = 159;
              "subject_name" = "Kano Class";
          }
      );
  },
      {
      "alarm_cnt" = 0;
  
      "class_id" = 71;
      "class_name" = Lagos;
      subject =         (
  
              "subject_id" = 160;
              "subject_name" = "Lagos Class";
          }
      );
  },
      {
      "alarm_cnt" = 3;
      "class_id" = 73;
      "class_name" = Nasarawa;
      subject =         (
  
              "subject_id" = 208;
              "subject_name" = "DOMA Class";
          },
  
              "subject_id" = 207;
              "subject_name" = "EGGON Class";
          },
  
              "subject_id" = 206;
              "subject_name" = "KARU Class";
          },
  
              "subject_id" = 209;
              "subject_name" = "LAFIA Class";
          },
  
              "subject_id" = 161;
              "subject_name" = "Nasarawa State Class";
          }
      );
  },
      {
      "alarm_cnt" = 2;
      "class_id" = 72;
      "class_name" = Rivers;
      subject =         (
  
              "subject_id" = 162;
              "subject_name" = "Rivers Class";
          }
      );
  }
  </code></pre>
  
  <p>)</p>
  
  <p>I have tried this here is my snippet </p>
  
  <pre><code>- (UITableViewCell *)tableView:(ExpandableTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  </code></pre>
  
  <p>{
      static NSString *CellIdentifier = @"RowCell";</p>
  
  <pre><code>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  NSDictionary *d=[_sitesJson objectAtIndex:0] ;
  NSArray *arr=[d valueForKey:@"subject_name"];
  NSDictionary *subitems = [arr objectAtIndex:0];
  NSLog(@"Subitems: %@", subitems);
  NSString *siteName = [NSString stringWithFormat:@"%@",subitems];
  cell.textLabel.text =siteName;
  //}
  NSLog(@"Row Cell: %@", cell.textLabel.text);
  // just change the cells background color to indicate group separation
  cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
  cell.backgroundView.backgroundColor = [UIColor colorWithRed:232.0/255.0 green:243.0/255.0 blue:1.0 alpha:1.0];
  
  return cell;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (UITableViewCell *)tableView:(ExpandableTableView *)tableView cellForGroupInSection:(NSUInteger)section
  </code></pre>
  
  <p>{
      static NSString *CellIdentifier = @"GroupCell";</p>
  
  <pre><code>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  UILabel *textLabel = (UILabel *)[cell viewWithTag:2];
  NSDictionary *d2 = [_regionsJson objectAtIndex:0];
  NSArray *arr2 = [d2 objectForKey:@"class_name"];
  NSString *regions = [[arr2 objectAtIndex:section]objectAtIndex:0];
  textLabel.textColor  = [UIColor whiteColor];
  textLabel.text = [NSString stringWithFormat: @"%@ (%d)", regions, (int)[self tableView:tableView numberOfRowsInSection:section]];
  NSLog(@"Group cell label: %@", textLabel.text);
  
  // We add a custom accessory view to indicate expanded and colapsed sections
  cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ExpandableAccessoryView"] highlightedImage:[UIImage imageNamed:@"ExpandableAccessoryView"]];
  UIView *accessoryView = cell.accessoryView;
  if ([[tableView indexesForExpandedSections] containsIndex:section]) {
      accessoryView.transform = CGAffineTransformMakeRotation(M_PI);
  } else {
      accessoryView.transform = CGAffineTransformMakeRotation(0);
  }
  return cell;
  </code></pre>
  
  <p>}</p>