0

I am using TableviewController. In which i used custom cell having a reply button.When I click on reply button then I want to add view in that same cell. This view is getting added but this cell height is not increasing. how to programatically increase cell height after button click in iOS. I used following code.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (indexPath.row==buttontag1)
   {
        pppp=[postText objectAtIndex:indexPath.row];
        CGSize maxSize = CGSizeMake(280, MAXFLOAT);//set max height
        CGSize cellSize = [pppp sizeWithFont:[UIFont systemFontOfSize:14]
        constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];

         //this will return correct height for text
          return cellSize.height+150;
   }
   else
   {
        pppp=[postText objectAtIndex:indexPath.row];
        CGSize maxSize = CGSizeMake(280, MAXFLOAT);//set max height
        CGSize cellSize = [pppp sizeWithFont:[UIFont systemFontOfSize:14]
        constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
        //this will return correct height for text
        return cellSize.height+100;
   }
}


 -(void)reply_comment:(UIButton*)sender
 {
      buttontag1=sender.tag;
      NSLog(@"I Clicked a button  button tag %d",buttontag1);
      NSString *child=[replyArray objectAtIndex:sender.tag];
      if(child== nil || child == (id)[NSNull null]||[child isEqualToString:@"0"])
      {
           NSLog(@"no child post");
      }
      else
      {        
          NSLog(@" child post");
         ChildViewController *objChildViewController=[[ChildViewController              alloc]initWithNibName:@"ChildViewController" bundle:nil];
         [cell.child setHidden:NO];
         [objChildViewController getchild:posts_id:buttontag1 :uid:frame2];
         [cell.child addSubview:objChildViewController.view];                   
       }
   }

Please can anyone help me out??

Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
Saba Sayed
  • 181
  • 2
  • 4
  • 11

1 Answers1

0

hope this helps.

@interface ViewController ()
{
int currentselection;
int cellno;
UITableView *table;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here

// set selection
cellno = indexPath.row;


}
-(void)buttonpressed
{
currentselection = cellno;
[table beginUpdates];
[table endUpdates];

}
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int rowHeight;
if ([indexPath row] == currentselection) {
    rowHeight = 200;
} else rowHeight = 100;
return rowHeight;
}
BalaChandra
  • 632
  • 9
  • 33