As If Prince
As If Prince

Reputation: 297

How to hide a UIView and set new height to UITable view in swift?

I have a UITable view in my View controller and a stackview at the bottom of the table view. I want the UITable view to go full view when stackview isHidden. Here is the code i write to do so :

                if response.total != 0.0{
                checkoutStackView.layoutIfNeeded()
                medDetailTableView.translatesAutoresizingMaskIntoConstraints = false
                medDetailTableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0).isActive = true
                vwPlaceOrder.isHidden = true
                viewCheckout.isHidden = true
                checkoutStackView.isHidden = true
            }else{
                checkoutStackView.layoutIfNeeded()
                viewCheckout.isHidden = false
                checkoutStackView.isHidden = false
                self.vwPlaceOrder.isHidden = false
                self.lblTotalItemsPrice.text = String(format: "%.1f",response.total)
                medDetailTableView.translatesAutoresizingMaskIntoConstraints = false
                medDetailTableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -70.0).isActive = true
            }

But this code is only showing the stackview but when the stackview is hidden UITableview is not going full view. Here is a image when stackview is showing: enter image description here And here is the image when stackview is hidden: enter image description here

Upvotes: 1

Views: 1117

Answers (2)

Igor
Igor

Reputation: 33

Try to use footer view of UITableView for placing your view. And make UITableView full size of it's superview. It should solve your problem.

Upvotes: 1

Omer Tekbiyik
Omer Tekbiyik

Reputation: 4764

When you hide a view in Swift , it just make it hide but constraints of hiden view is still alive. So you must to set 0 this height constraints.

For this you can create an outlet of Constraints and change it like :

  @IBOutlet weak var heightConstt: NSLayoutConstraint!

And when you hide stackView change its constraint

  heightConstt.constant = 0

Upvotes: 0

Related Questions