4

I'm trying to set a constraint on 2 views so that they touch each other like this:

enter image description here

I tried setting constraints programmatically:

[self addConstraint:[NSLayoutConstraint constraintsWithVisualFormat:@"[_firstView][_secondView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_firstView, _secondView)]];

But I get the following warning:

Incompatible pointer types sending 'NSArray *' to parameter of type 'NSLayoutConstraint'

What am I doing wrong?

1 Answer 1

2

The addConstraint: method expect a single constraint, however the constraintsWithVisualFormat: returns an NSArray of zero or more constraints.

Try adding an s.

[self addConstraints:/*your NSLayoutConstraint constraintsWithVisualFormat: call */];

Apple's naming conventions can usually help you out here. Notice that constraintsWithVisualFormat is plural while addConstraint: was singular (and addConstraints: is plural). Use these as your clue in the future.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh! Thanks!! And just to make sure, the constraint I have will do I the image shows? Meaning flush the 2 views top to bottom?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.