Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:37:48+00:00 2026-06-16T03:37:48+00:00

I have some trouble with NSLayoutConstraint . NSLayoutConstraint gives me an exception if I

  • 0

I have some trouble with NSLayoutConstraint.

NSLayoutConstraint gives me an exception if I try to alter constant using the setConstant: method. I only have this problem when I add the height constraint via code.

First off, I’m getting the height constraint like so:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", NSLayoutAttributeWidth];
NSArray *filteredArray = [[self constraints] filteredArrayUsingPredicate:predicate];
return filteredArray[0];

Which gives me the right constraint. I have a NSTextField subclass where this works perfectly. The constraints are set in the Interface Builder, and I can set and alter the constant.

Now I have a view, where I add different subviews at run-time.
Those subviews are located in own NIBs, which means I can’t pin their width and height.
So I thought I’d add the constraints as soon as the view is being added to a superview.
This is being executed in viewDidMoveToSuperview.

// Pin Width & Height
[self addConstraint:[NSLayoutConstraint constraintWithItem:self
                             attribute:NSLayoutAttributeWidth
                             relatedBy:NSLayoutRelationEqual
                                toItem:nil
                             attribute:NSLayoutAttributeNotAnAttribute
                            multiplier:1.0f
                              constant:self.frame.size.width]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self
                                                 attribute:NSLayoutAttributeHeight
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:nil
                                                 attribute:NSLayoutAttributeNotAnAttribute
                                                multiplier:1.0f
                                                  constant:self.frame.size.height]];

The constraints are added, I can confirm this with an NSLog.

"<NSLayoutConstraint:0x100605cc0 H:[ITControlPanelChildView:0x100616eb0(269)]>",
"<NSLayoutConstraint:0x100614410 V:[ITControlPanelChildView:0x100616eb0(317)]>"

Now, finally, when I try to alter the constraint using [constraint setConstant:somethingDifferent]; I get the following exception:

Unable to simultaneously satisfy constraints:
(
    "<NSLayoutConstraint:0x10192fcb0 V:[ITControlPanelChildView:0x10192e4f0(100)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x10053ff10 h=--& v=&-- V:[ITControlPanelChildView:0x10192e4f0(317)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x10192fcb0 V:[ITControlPanelChildView:0x10192e4f0(100)]>

This is exactly the constraint I’m trying to change.
Can anyone explain to me why this is happening?


EDIT

I just read that the NSAutoresizingMaskLayoutConstraints are added automatically, which you can disable if you set [self setTranslatesAutoresizingMaskIntoConstraints:NO];.

If I disable it, it works.

Even better would be if I could access the NSAutoresizingMaskLayoutConstraint which are created. Does anyone know how this works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:37:49+00:00Added an answer on June 16, 2026 at 3:37 am

    As indicated in the rest of the log message that you haven’t included, you’ve got autoresizing constraints that you don’t want or need.

    You can remove these when you add the subview. In the method you’re using above, just add this line:

    self.translatesAutoresizingMaskIntoConstraints = NO;
    

    Though if you are creating the view in a separate nib, where is it getting its size from? Doesn’t it already have size constraints which you can just create outlets to?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble while try using broadcast receiver. Target: I have three app
I have some trouble when using SPUtility.SendEmail method in a custom workflow. private void
I have some trouble with dbus-send when using a{sv} Calling a method with in_signature='a{ss}'
I have some trouble when I try to map object to int . My
i have some trouble writing a method in Objective-C to make an object nil.
I have some trouble matching the contents inside php tags. Currently I have this
I have some trouble with returning the message popup in mvc3 when some exception
I have some trouble with creating window application using PyQt. For example: we have
I have some trouble understanding this one so here it is. I'm trying to
I have some trouble with using authlogic in my rails app, so I began

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.