0

I have a custom uitableviewcell.

i want to change its height based on some if condition. How can i be able to do this ?

I tried doing this in cellForRowAtIndexPath -

if (cell.newsFeedImage.image == NULL)
{
    NSLog(@"NULL");
    cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20);
}

The log message appears, but the frame never changes.

Please help.

Ashish Gogna
  • 59
  • 2
  • 6
  • 1
    possible duplicate of [Setting custom UITableViewCells height](http://stackoverflow.com/questions/494562/setting-custom-uitableviewcells-height) – Szu Sep 29 '14 at 11:05

3 Answers3

1

try to do this in heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    CustomCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    if (cell.newsFeedImage.image == nil) {
        cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20);
    } 
    else return 40;
}
lassadt
  • 21
  • 4
0

The height of the cell is set in the tableView datasource method

heightForRowAtIndexPath

Thallius
  • 2,482
  • 2
  • 18
  • 36
0

It's a little more complicated than that.

This questions has been answered at great length here: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

Community
  • 1
  • 1
Albin Stigo
  • 2,082
  • 2
  • 17
  • 14