0

I'm a new in the programming and I know that there are a lot of staff about auto-layout or manipulation with constraints in the internet/stackoverflow and I searched everywhere however was unable to find answer on my question, so please advise if you can. For example here is UI example

So I have a tableView which is top constaints to top of ViewController and textView which is top constraints to bottom of tableView. So the question is, how can I dynamically change constraints based on the size of array in TableView. If TableView is empty, so then assign textView to ViewController, if array of tableView > 0, then assign to bottom of TableView. I tried something like this

@IBOutlet weak var textViewTopConstraints: NSLayoutConstraint! {
        didSet {
            if array.isEmpty {
                textViewTopConstraints.isActive = false
                textView.topAnchor.constraint(equalTo: ViewController.top, constant: 8).isActive = true
            } else if imageURL.count > 0 {
                textViewTopConstraints.isActive = false
                textView.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 8).isActive = true
            }
        }
    }

However it's only working when app is loaded and then didn't call if array is changed. So basically, I can't understand how to call function or something that will track and change my constraints based on the size of my array. If this is a duplicate, could you please guide me to the right link where I can check this information.

Sargot
  • 73
  • 2
  • 6

1 Answers1

0

Change table view frame and connect constraints between textfield and table view. Link to set table view frame is :- Change UITableView height dynamically

Jitendra Tanwar
  • 249
  • 2
  • 11
  • Yes, it basically will set height of tableView with the height of your content size but if my content size initially has outlets for imageView and some labels? The content size will already have a height and my textView will not start from the top of ViewController if tableView is empty and there will be an empty space with the size of content size of tableView – Sargot Jun 18 '17 at 18:14
  • No it has nothing to do with images and lables in cell until there is any cell to make . – Jitendra Tanwar Jun 18 '17 at 18:48