How to adjust the height of the cell table when loading from the custom cells?

后端 未结 3 1278
臣服心动
臣服心动 2021-01-27 09:07

I have an application in which I am loading a UITableView from 3 types custom cells. I made 3 custom classes for that and added all the elements Progra

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-27 09:46

    Please check the custom cell height will be the same as table view each cell height.

    You can use following function to adjust table view's cell height.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return height;
    }
    

    You can use code like this.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        Defination *definition = [self.dataSource objectAtIndex:indexPath.row];
        NSString *detailString = definition.detailString;
        CGSize detailSize;
        detailSize = [detailString sizeWithFont:fontSize(12.0) constrainedToSize:CGSizeMake(420, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
    
        return detailSize.height + 20.0;
    }
    

提交回复
热议问题