I'm seeing warnings in the console when I dynamically make autolayout 
constraints active/inactive at runtime.

I have two constraints that align a container view leading or trailing edge 
with another view's edge. This is to move the container onscreen or offscreen. 
I have another view whose trailing edge aligns with the leading edge of the 
first container view so it moves with it as autolayout constraints change.

At runtime, I make one of these constraints active and the other inactive, like 
so:

- (IBAction)toggleCommentsVisibility:(id)sender
{
        self.commentsAreHidden ? [self showComments:self] : [self 
hideComments:self]; 
}

- (IBAction)showComments:(id)sender
{
        self.showCommentsConstraint.active = YES;
        self.hideCommentsContainerConstraint.active = NO;

        self.commentsAreHidden = NO;
}

- (IBAction)hideComments:(id)sender
{
        self.showCommentsConstraint.active = NO;
        self.hideCommentsContainerConstraint.active = YES;

        self.commentsAreHidden = YES;
}

When I call showComments, I get the following warning in the console:

=====

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't 
want. 
Try this: 
        (1) look at each constraint and try to figure out which you don't 
expect; 
        (2) find the code that added the unwanted constraint or constraints and 
fix it. 
(
    "<NSLayoutConstraint:0x7f91426a3ef0 'CommentContainerProportionalWidth' 
UIView:0x7f91426d9db0.width == 0.33*UIView:0x7f91426def30.width>",
    "<NSLayoutConstraint:0x7f91426c91e0 'Hide Comments Constraint' 
H:[UIView:0x7f91426d7f00]-(0)-[UIView:0x7f91426d9db0]>",
    "<NSLayoutConstraint:0x7f91426e2990 'ShowComments' 
UIView:0x7f91426d9db0.trailing == UIView:0x7f91426d7f00.trailing>",
    "<NSLayoutConstraint:0x7f91427e43c0 'UIView-Encapsulated-Layout-Width' 
H:[UIView:0x7f91426def30(768)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f91426c91e0 'Hide Comments Constraint' 
H:[UIView:0x7f91426d7f00]-(0)-[UIView:0x7f91426d9db0]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch 
this in the debugger.

=====

This is puzzling because IB doesn't give me any autolayout errors/warning when 
I manually activate/deactivate these constraints. Also, I don't get this 
runtime warning when calling hideComments, only the 'show' case. Finally, 
things actually work at runtime because it's nice enough to "break" the 
constraint that I deactivated in code. But I would like to not have these 
warnings.

Any ideas on what's going on how I might go about debugging this?

Doug Hill
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to