0

How to resize the height of tableview ? I can achieve ,when the screen is initially loaded. But when we add data in add screen . we traverse from add screen to display screen. Height of the tableview not reflected. when I close the application and reopened the height get changed. Only the height of tableview is not reflected.But the data got reflected.

 func tableSize(count:Int,tableView:UITableView) {
        switch count {
            case 0:
                    tableView.heightAnchor.constraint(equalToConstant: 80).isActive = true
            case 1:
                    tableView.heightAnchor.constraint(equalToConstant: 95).isActive = true
            case 2:
                    tableView.heightAnchor.constraint(equalToConstant: 115).isActive = true
            case 3:
                    tableView.heightAnchor.constraint(equalToConstant: 155).isActive = true
            case 4:
                    tableView.heightAnchor.constraint(equalToConstant: 200).isActive = true
            default:
                    tableView.heightAnchor.constraint(equalToConstant: 250).isActive = true
        }
        tableView.layer.borderColor = UIColor.blue.cgColor
        tableView.layer.borderWidth = 1.0

    }
BoR
  • 83
  • 3
  • 11

1 Answers1

0

Well, doing this you are not updating the constraint; only adding new ones.

You should declare a NSLayoutConstraint variable in your view controller, assign it the tableView's height constraint, then update it's constant whenever you need to, before finally calling view.layoutIfNeeded()

See How to update the constant height constraint of a uiview programatically

ElFitz
  • 908
  • 1
  • 8
  • 26