1
votes

I have an UIViewController that contains the main UIView and inside of this are a small UIView on the top and a UITableView that fills the rest of the space.

All the design has been done with Storyboards and autolayout, so basically there are these constraints for the upper UIView:

  • Top space = 0px to superview
  • Leading space = 0px to superview
  • Trailing space = 0 px superview
  • Height = 44px

And these for the UITableView:

  • Top space = 0px to UIView
  • Bottom space = 0px to superview
  • Leading space = 0px to superview
  • Trailing space = 0 px superview

Everything works fine and resizes properly when using a different screen size or orientation. What I am trying to do now is deleting the top UIView programmatically and then I want the UITableView to fill the space to the top of the superview.

I know I could create programmatically a new constraint for the UITableView, but what I am looking for is for a low-priority-constraint? already defined in the Storyboard that can coexist with the ones already defined before.

Any other trick or workaround would be also appreciated, the only restriction is that everything should be designed in the Storyboard and everything should work after calling:

[view removeFromSuperview];

Here is the design:

screenshot

3
Is it absolutely required to remove the top view? If not, you could animate changing the height of the top view to 0 (zero), or you could animate changing the top view's top constraint constant from 0 to -44, which would animate the view sliding off the top of the screen. In either case, the table view should take up the "extra" space and will do so in an animated fashion, to boot!mbm29414

3 Answers

0
votes

just update the tableview's frame to fill the entire window after you removed the top view from it's superview

0
votes

You only need to add another top constraint, one to the top layout guide, and then edit it to have a priority of 900, and a constant value of 0. If you already have the top view in place, you'll have to drag from your lower view to the main view in the list on the left since you won't be able to access the main view in the canvas.

0
votes

Its very easy, as you have already made Height constraint for top UIView and vertical space constraint between top view and table view.

Create instance of Height constraint in respective implementation (.m) class.

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topViewHeightConstraint

then when you don't want top view, write topViewHeightConstraint.constant = 0.f

As you have already made vertical space constraint between top view and table view, table view will take whole space of super view.

When you want top view again just set constraints value.