I have created a custom cell table view.This custom cell contains labels so i have added labeled from storyboard & i show data on them from server.So if there is no data for the label then i hide the label but if there is data then i show the label with server data.So teh height of cell remain lets say 180 if there is data on label or not because label remain always there.Now when there is no data for the label then i want to remove or hide label & decrease the height of cell because all labels shown vertically.In this way i wan to calculate the height of cell.

**Problems with HeightForAtIndex**

* How to access cell in heightForRow?
* What code to write i get the cell in heightForRowAtIndex?

**EDIT:**

I have tried this code:

```
-   (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

      float like_height,c_one_height,c_two_height,c_three_height,tv_height,header_height,operations_height;
    //define variables here
    if(!self.customCell)
    {
        self.customCell = [self.table_view dequeueReusableCellWithIdentifier:@"homeCell"];
    }
     Post *user_post=[arr_post objectAtIndex:indexPath.row];
     int like_count=[user_post.like_count intValue];
    float comment_count=[user_post.comment_count intValue];
    [self.customCell setSelectionStyle:UITableViewCellSelectionStyleNone];

    if(like_count>0)
    {
        like_height=self.customCell.label_like_count.frame.size.height;

    }
    else
    {
        like_height=0;
    }
    if(comment_count<=0)
    {
        c_one_height=0;
        c_two_height=0;
        c_three_height=0;

    }
    else if(comment_count==1)
    {
        c_one_height=self.customCell.first_comment.frame.size.height;
        c_two_height=0;
        c_three_height=0;

    }
    else if(comment_count==2)
    {
        c_one_height=self.customCell.first_comment.frame.size.height;
        c_two_height=self.customCell.second_cmment.frame.size.height;
        c_three_height=0;
    }
    else if(comment_count==3)
    {
        c_one_height=self.customCell.first_comment.frame.size.height;
        c_two_height=self.customCell.second_cmment.frame.size.height;
        c_three_height=self.customCell.third_comment.frame.size.height;
    }
    tv_height=self.customCell.view_tvContainer.frame.size.height;
    header_height=self.customCell.header_view_height.frame.size.height;
    operations_height=self.customCell.view_operations_height.frame.size.height;
    CGFloat height = like_height+c_one_height+c_two_height+c_three_height+tv_height+header_height+operations_height;
    // Padding of 1 point (cell separator)
    CGFloat separatorHeight = 1;
    return height + separatorHeight;
}

```