0

hello I am new to IOS and I am struggling in one functionality which I am trying to implement. I have a UIViewController in which I am showing a custom UIView on the top and the below I have a dynamic TableView. I am hiding and showing the custom UIView on some conditions but the problem is If I hide it, my table don't take a place of that view so I can see the space over there. I think I have do something with the autolayout but I am not good in autolayout so If any one can help would be great. I am attaching a demo screens here so that you can understand. What should I do to make it work so that table will take the custom UIView place when UIView is hidden

enter image description here

This is the result I am getting If I hide the above portion Custom UIView

enter image description here

hellosheikh
  • 2,929
  • 8
  • 49
  • 115

1 Answers1

5

in order to achieve this functionality you need to do the following steps:

  1. Create height constraint for your top view and save it in @IBOutlet

@IBOutlet weak var topViewHeightConstraint : NSLayoutConstraint!

  1. When you are hiding your top view change also your height constraint to 0 in order that the tableview will take its place . in order to change it to 0 you just need to change the constant value to 0

topViewHeightConstraint.constant = 0

enter image description here

Link for downloading a swift project that show how to do it can be found here

Ran Hassid
  • 2,788
  • 1
  • 12
  • 20