UITableViewAutomaticDimension

跟風遠走 提交于 2020-02-22 05:30:06

问题


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?


回答1:


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




回答2:


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.




回答3:


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;

}


来源:https://stackoverflow.com/questions/26308510/uitableviewautomaticdimension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!