0

I have a custom tableview cell, if the cell is clicked then the cell should be expanded and if not clicked then the cell should not be expanded.

There is also a custom view and if the cell is clicked, I want the height of the custom view to be increased and if the cell is not clicked then it should be a certain height.Below this code is set in cellForRowAt

 if TableView.rowHeight == 126 {

            cell.CustomView = UIView(frame: CGRect(x: 7, y: 8, width: 359, height: 20))

            return cell
        }
        else{

        }

But the code I set to change the height of the view is not working and I am not sure where to go from there

When the cell is not clicked this is how my custom View looks like:enter image description here

When the cell is clicked this is what the custom view looks like:enter image description here

As you can see my problem is when the cell is not clicked, the bottom of the View is a straight line but when the cell is clicked, the bottom is rounded. I want the View to also be rounded when the cell is not clicked.

juelizabeth
  • 485
  • 1
  • 8
  • 31

2 Answers2

1

Call beginUpdates and endUpdates to force tableView to update heights

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // new row selected
    self.selectedIndex = indexPath
    tableView.beginUpdates()
    tableView.endUpdates()
}

See also

Jože Ws
  • 1,754
  • 17
  • 12
  • it updates the height of the cell, the only thing it doesn't do is update the height of the view. The view is set at a height of 300 and when it is clicked, the height remains 300 but when it is not clicked the height of the view is still 300 – juelizabeth May 29 '17 at 23:57
1

Add the code below . Hope this is gonna help you .

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        //performSegue(withIdentifier: "toDetail", sender: self)
        self.isExpanded = true
        self.selectedIndex = indexPath
        tableView.beginUpdates()
        tableView.endUpdates()
        self.isExpanded = false
    }
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {

        self.selectedIndex = IndexPath()
        tableView.beginUpdates()
        tableView.endUpdates()
    }

Courtesy : @Jože Ws

roy
  • 6,685
  • 3
  • 26
  • 39
  • I have updated my question to hopefully make my question a little clearer Thank you very much – juelizabeth May 30 '17 at 09:51
  • the update of your question have turned into entirely different question ( although still not enough clear ) . so , next time form a clear question before someone has invested his time on it . @juelizabeth – roy May 30 '17 at 10:52
  • I'm sorry, you wasted your time – juelizabeth May 30 '17 at 11:04