-1

I have a UITableViewContoller with a a UITableViewCell that has a UIButton. When the UIButton is tapped, I would like the cell's height to resize to 100, and when tapped again, the cell's height should resize to 300.

I have done this using Autolayout before where I change the height constraint.

Is there a way to do this without using Autolayout using Autoresizing:

enter image description here

If so, what are the steps?

user1107173
  • 10,334
  • 16
  • 72
  • 117
  • 1
    Possible duplicate of [Can you animate a height change on a UITableViewCell when selected?](https://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected) – TheCodingArt Jul 15 '17 at 15:41
  • If you know how to do it with Autolayout, why in the world do you want to do it a different way? – DonMag Jul 15 '17 at 16:46
  • @DonMag I find using Autoresizing option much easier than Autolayout. Wanted to see if there is a way. – user1107173 Jul 15 '17 at 22:09
  • Basically, implement `heightForRowAtIndexPath` and do your cell-content height calculations there. It's been quite a while since I did that, so my approach would be to search, but set a date restriction to pre-autolayout times. Found this which looks like a decent tutorial on *how* to go about it: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/ – DonMag Jul 15 '17 at 22:18
  • Thank you for getting that link. I am aware of that method. Wasn't sure if there is a new way since Autoresizing resurfaced. – user1107173 Jul 15 '17 at 22:20
  • @user1107173 I'm not sure what you mean. Autoresizing has not resurfaced. Autolayout is the correct approach for resizing 99% of the time and is the preferred layout engine to use. Autoresizing translates into the auto layout engine now-a-days, and generally should not be applied to new projects in practice. Intrinsic resizing based off of auto layout is also 100% different than setting autoresizing rules. – TheCodingArt Jul 15 '17 at 23:41

1 Answers1

1

You tell a tableView to begin updates and reload the cell with a new height provided by the delegate methods, then call endUpdates on the tableView. Honestly, this question is a simple google search away with plenty of online tutorials.

TheCodingArt
  • 3,436
  • 4
  • 30
  • 53
  • How is this a duplicate? Where in that answer does it talk about using 'Autoresizing' as an alternative to 'Auto-layout'? Since this is a simple Google search, then can you provide me a link and your Google search string that talks about using 'Autoresizing' as an alternative to 'Auto-layout`? – user1107173 Jul 15 '17 at 21:55
  • @user1107173 You override height for row and provide a new height. This is noted in the link attached marking this question as a duplicate. – TheCodingArt Jul 15 '17 at 23:39