Egor Kuznetsov - 11 months ago 61

iOS Question

I have multiple dynamic cells with a different row height. So, I am trying to update row height with a method estimatedHeightForRowAtIndexPath

This is my code:

`override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {`

switch indexPath.row {

case 0:

return 132

case 1:

return 66

case 2:

return 80

case 3:

return 70

case 4:

return 50

case 5:

return 60

case 6:

return 60

default:

return 60

}

}

But, row height doesn't update. It's using estimated row height from Storyboard. What is the problem?

Answer Source

In youre case you should use method `heightForRowAtIndexPath`

.

Use `estimatedHeightForRowAtIndexPath`

when you would like to use auto resized cells.

Providing an estimate the height of rows can improve the user experience when loading the table view. If the table contains variable height rows, it might be expensive to calculate all their heights and so lead to a longer load time. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.

```
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
switch indexPath.row {
case 0:
return 132
case 1:
return 66
case 2:
return 80
case 3:
return 70
case 4:
return 50
case 5:
return 60
case 6:
return 60
default:
return 60
}
}
```