3

I have a table view which has dynamic cells created by code. In IOS 7 to make sure the cell is displayed fully, I override the method heightForRowAtIndexPath

overriding this method in ios8 seems to make my cells just be one on top of the other, and all sized 67.0003

I do not want to create an autolayout layout for the cells, they are too complex and already made

Is there a way to fix the height issue in ios 8?

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

3 Answers3

3

UITableViewAutomaticDimension is only working with autolayout. If you don't use autolayout, don't use something like

self.tableView.rowHeight = UITableViewAutomaticDimension;

It would be helpful if you could provide your controller's code.

Tuan
  • 893
  • 1
  • 9
  • 24
  • how do i disable it ? and let the system allow me to do the calculation ? – Lena Bru Oct 11 '14 at 02:40
  • try to set self.tableView.estimatedRowHight = 44; just leave .rowHeight out and override heightForRowAtIndexPath. – Tuan Oct 11 '14 at 12:10
  • as mentioned in the post, overriding the heightForRowAtIndexPath in ios8 makes all the rows be one on top of the other. And if i don't override them, they are all set to be 67 points high – Lena Bru Oct 11 '14 at 13:14
  • Could you upload some test project? – Tuan Oct 11 '14 at 18:07
3

There is no problem with the method heightForRowAtIndexPath, it works well in ios8 as well The problem was in my heightForRowAtIndexPath i wrote

CGSize size;
a bunch of ifs
size.height = something

and in other cases i had

size.height+= something

and size.height was not always 0 at start

Lena Bru
  • 13,521
  • 11
  • 61
  • 126
0

If you want dynamic cell hight you need to set size of cell first

For example: you want to give some text info in every tableview cell first you need to calculate the height of cell according to the and then set the height of cell in heightForRowAtIndexPath

     - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
    NSString* text= [yourArray objectAtIndex:indexPath.row];
    CGSize textSize= [text getTextSize];

    if (textSize<SomeMinValue)
    {
        textSize= CGSizeMake(cellWidth, SomeMinValue)
    }

    return textSize.height;

}
samanvith
  • 39
  • 3