1

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

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114

2 Answers2

1

You need to reload the table view after you change anything in it like so:

tableView.reloadData()

When you scroll away from the cell, if it goes off the screen it is unloaded. When you scroll back up, it reloads it. You are basically just reloading the data as scrolling would do.

brimstone
  • 3,370
  • 3
  • 28
  • 49
0

This code should work here:

tableView.reloadData()

It will reload the table everytime you changes something.

Source

pguetschow
  • 5,176
  • 6
  • 32
  • 45
  • Great! Any idea if this approach allows me to add animation? – Greg Peckory Aug 21 '15 at 08:42
  • `UIView.animateWithDuration` should help there. For further informations visit [https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html] – pguetschow Aug 21 '15 at 08:49
  • Do I put `tableView.reloadData()` inside that? – Greg Peckory Aug 21 '15 at 08:50
  • Look at this @GregPeckory: http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected – brimstone Aug 21 '15 at 09:17