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.
Self sizing specific UITableView Cell
238 views Asked by uzair shahzad At
2
There are 2 answers
2
On
You can check which cell you need to return dinamicHeigth and in func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
return UITableViewAutomaticDimension
according
Example code using row 0 as condition
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if(indexPath.row == 0)
{
return UITableViewAutomaticDimension
}
return 88
}
You have to know which rows that you want to implement the
UITableViewAutomaticDimension
for because when because whenheightForRowAt
is called, no cells are created yet so you can´t check the cell type ye that´s why you need to check theindexPath.row
instead.Something like this for example: