Search code examples
swiftuitableviewautolayoutcontentsize

Self sizing specific UITableView Cell


I know how to make UITableViewCells self size in UITableView. The question is how to only a specific cell self size itself. I have four different custom UITableView Cells in my table and I want to make only one cell self size itself.


Solution

  • You have to know which rows that you want to implement the UITableViewAutomaticDimension for because when because when heightForRowAt is called, no cells are created yet so you can´t check the cell type ye that´s why you need to check the indexPath.row instead.

    Something like this for example:

    switch indexPath.row {
    case 0:
        return 100
    case 1,2,3:
        return UITableViewAutomaticDimension
    default:
        return 100
    }