0

I have a View in the Storyboard, which shows an error message. I remove this at load using

[self.ErrorView removeFromSuperView];

Later on in the code, I then want to show the view, using

[self.MainView addSubview:self.ErrorView];

this does show the view, but the view is only sized by the content within in, where as on the story board it is size to full width using the 'Leading/Trailing Edge' constraints.

How do I refresh the view's constraints to match those on the storyboard.

Robert
  • 3,790
  • 1
  • 27
  • 46
James Walker
  • 69
  • 1
  • 8
  • [This question](http://stackoverflow.com/questions/18617991/what-happens-with-constraints-when-a-view-is-removed) may help explain what happens and what to do. When you remove a view, the constraints are removed as well. – j.f. May 01 '15 at 19:56

3 Answers3

0

Make a strong private property outlets to those two constraints. When you need to re-add the view to the view hierarchy again, you just add those two constraints back into the hierarchy using the addConstraint method.

    [self.parentView addConstraint:self.constraintX];
Earl Grey
  • 7,426
  • 6
  • 39
  • 59
0

As far as I understood, you want to only show and hide view in UIViewController? If that is your purpose you should use this code:

self.ErrorView.hidden = YES;  // To hide alert

and

self.ErrorView.hidden = NO;  // To show alert
Ch0k0l8
  • 827
  • 6
  • 14
Robert
  • 3,790
  • 1
  • 27
  • 46
0

Take all constraints using [self.ErrorView constraints]; then loop through it and find the constraint that has ErrorView as one of the item that it constraints on and then add that constraint to the ErrorView using

[self.ErrorView addConstraint: retrievedConstrainted]; 
Ch0k0l8
  • 827
  • 6
  • 14