Question: [Here in this image the first section is not expanded whereas second section expands on click.](http://i.stack.imgur.com/KYp4T.png)

also the expanded cells should go to a viewcontroller on didselect
the data in the rows of all sections are static.
How can i acheive this in objective c?? i tried searching for the question but couldnt find any.

Answer: 
Use the following code to drop Expandable Cells into a UITableView:

```
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text=[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"name"];
    [cell setIndentationLevel:[[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];    
    return cell;
}

```

Code for expanding & collapsing rows goes in your TableView's `DidSelectRow` method:

```
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row];
    if([d valueForKey:@"Objects"]) {
        NSArray *ar=[d valueForKey:@"Objects"];
        BOOL isAlreadyInserted=NO;
        for(NSDictionary *dInner in ar ){
            NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted=(index>0 && index!=NSIntegerMax);
            if(isAlreadyInserted) break; 
        }
        if(isAlreadyInserted) {
            [self miniMizeThisRows:ar];
        } else {        
            NSUInteger count=indexPath.row+1;
            NSMutableArray *arCells=[NSMutableArray array];
            for(NSDictionary *dInner in ar ) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [self.arForTable insertObject:dInner atIndex:count++];
            }
            [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
        }
    }
}

```

Finally, a method to help minimize-maximize/expand-collapse rows:

```
-(void)miniMizeThisRows:(NSArray*)ar{
    for(NSDictionary *dInner in ar ) {
        NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner];        
        NSArray *arInner=[dInner valueForKey:@"Objects"];
        if(arInner && [arInner count]>0){
            [self miniMizeThisRows:arInner];
        }
        if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
            [self.arForTable removeObjectIdenticalTo:dInner];
            [self.tableView deleteRowsAtIndexPaths:
              [NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexToRemove inSection:0]]
                      withRowAnimation:UITableViewRowAnimationRight];
        }
    }
}

```

[Download code from here](http://sugartin.info/)
> 
> First i created properties for each static cell and in viewDidLoad i set them as hidden:
> 
> 
> 

```
- (void)viewDidLoad
{
 [super viewDidLoad];
 isExpanded = NO;
 self.cell2.hidden = YES;
 self.cell3.hidden = YES;
 self.cell4.hidden = YES;
}

```

> 
> Then in DidSelectRowAtIndex:
> 
> 
> 

```
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath section]== 1 && [indexPath row]==0)
{
    new1 =[NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
    new2 =[NSIndexPath indexPathForRow:indexPath.row+2 inSection:indexPath.section];
    new3 =[NSIndexPath indexPathForRow:indexPath.row+3 inSection:indexPath.section];
    self.cell2 = [super tableView:tableView cellForRowAtIndexPath:new1];
    self.cell3 = [super tableView:tableView cellForRowAtIndexPath:new2];
    self.cell4 = [super tableView:tableView cellForRowAtIndexPath:new3];
    CATransition *animate = [CATransition animation];
    animate.type = kCATransitionMoveIn;
    animate.duration = 0.4;

    [self.cell2.layer addAnimation:animate forKey:nil];
    [self.cell3.layer addAnimation:animate forKey:nil];
    [self.cell4.layer addAnimation:animate forKey:nil];

    if (isExpanded == NO)
    {
        self.cell4.hidden = NO;
        self.cell2.hidden = NO;
        self.cell3.hidden = NO;
        isExpanded = YES;        }
    else
    {
        isExpanded = NO;
        self.cell4.hidden = YES;
        self.cell2.hidden = YES;
        self.cell3.hidden = YES;

    }
}
}

```

I am not sure how good it is.. if there are any mistakes please letme know as i m quite new to objective c.