0

I'm want to expand and collapse cells in my table view without heightForRowAt(). I want only using Layout Constraints.

I have read Self-sizing Table View Cells and check the solution in this post

And now I have a problem: when I touch my cell in table View it not happening, when i double touch on that, it's working; something just once. i don't understand what happened.

this video what happing: (link)

this is my code

Alex Sergeenko
  • 642
  • 5
  • 22
Long Vu
  • 160
  • 1
  • 11

2 Answers2

0

Your problem is that you placed the isExpanded logic inside the cell itself which may be dequeued and result in wrong values , you need to place it in your model like this , so create an array of Content

struct Content {
   var title:String
   var subTitle:String
   var isExpanded:Bool
}

//

See full edit Here ( Sorry not on github & excluded the video asset )

//

enter image description here

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

After select the tableview's cell cell.isExpanded flag change to true but tableView.reloadRows(at: [indexPath], with: .fade) this code call your cellforindex mehtod and create new cell. so your logic goes wrong because of reusability of cell.

Vishal Patel
  • 511
  • 6
  • 21