UITableViewAutomaticDimension

I have a table view that has dynamic cells generated by code. In IOS 7

to make sure the cell is fully displayed, I override the methodheightForRowAtIndexPath

overriding this method in ios8 seems to force my cells to just be one on top of the other and everything is 67.0003

I do not want to create an auto audit mockup for cells, they are too complex and already done

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

+3


source to share


3 answers


No problem with heightForRowAtIndexPath method, it works well in ios8 too The problem was 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

not always 0 at startup

+3


source


UITableViewAutomaticDimension only works with autoloading. If you are not using autorun, then don't use something like

self.tableView.rowHeight = UITableViewAutomaticDimension;

      



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

+3


source


If you want dynamic cell height you need to set cell size first

For example: you want to provide some text information in each table cell, first you need to calculate the cell height according to it and then set the cell height to 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;

}

      

0


source







All Articles