Search code examples
iosswiftuitableviewheightcell

Dynamically updating cell height without having to scroll Swift


By default the height of my cell is set to 140.

But if expanded, it should be set to 265.

This is what I have:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    if(expanded){
        return 265.0
    }else{
        return 140.0
    }
}

The problem is, I need to scroll down, and scroll back up for the cell to change height. How do I fix this?

Secondary question (more interested in the above question, just if anyone happens to know)

Is it possible to have the cell animate from height 140 to 165?

Thanks


Solution

  • This code should work here:

    tableView.reloadData()
    

    It will reload the table everytime you changes something.

    Source