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 8908209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:07:18+00:00 2026-06-15T03:07:18+00:00

Within my root view controller, I’m adding a child view controller’s view as a

  • 0

Within my root view controller, I’m adding a child view controller’s view as a subview, as follows:

ChildViewController *cvc = [[ChildViewController alloc] init];
[self addChildViewController:cvc];
[self.view addSubview:cvc.view];
[cvc didMoveToParentViewController:self];

and I’d now like to use a NSLayoutConstraint to position the cvc.view within the parent view (self.view), such that cvc.view is positioning 25 pts above the bottom of the parent view. My understanding is that the following should work:

UIView *superview = self.view;
UIView *childview = cvc.view;
NSLayoutConstraint *cn = 
    [NSLayoutConstraint withItem:childview 
      attribute:NSLayoutAttributeBottom 
      relatedBy:NSLayoutRelationEqual 
      toItem:superview attribute:NSLayoutAttributeBottom 
      multiplier: 1.0 
      constant: -25.0];
[superview addConstraint: cn];

But the constraint fails at runtime. I thought initially maybe the autoresizing mask in the child view was causing problems (and following the WWDC 2012 Intro video on auto layout), so I set [childview setTranslatesAutoresizingMaskIntoConstraints:NO], but then the childview simply fails to appear.

What am I doing wrong?

  • 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-15T03:07:19+00:00Added an answer on June 15, 2026 at 3:07 am

    I’m not sure but the following should work, or something very similar:

    UIView *superview = self.view;
    UIView *childview = cvc.view;
    NSDictionary *constrainedViews = NSDictionaryOfVariableBindings(childview);
    NSArray *constraints =
    [superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[childview]-25-|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:constrainedViews];
    

    If not make sure that you are actually setting a size for the childview, something like:

    UIView *superview = self.view;
    UIView *childview = cvc.view;
    NSDictionary *constrainedViews = NSDictionaryOfVariableBindings(childview);
    NSArray *constraints =
    [superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[childview]|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:constrainedViews];
    

    Say, to make it fill the width of the view. Or:

    UIView *superview = self.view;
    UIView *childview = cvc.view;
    NSDictionary *constrainedViews = NSDictionaryOfVariableBindings(childview);
    NSArray *constraints =
    [superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[childview(>100,<304)]-|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:constrainedViews];
    

    Which means something like childview should have a width bigger than 100 but less than 304 with default margins to the superview. Please note I don’t know if the above constraint actually makes sense (e.g. it may just always give you 304 width childview as that would leave default margins), but it serves as an example.

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

Sidebar

Related Questions

Ok here is what i am trying to do. In my root view controller
My application launches into a navigation controller. The root view controller has a button
I am currently working within a WPF user control (the root element of my
Is there a way to specify the root directory at runtime within a program's
I have two directories within my codeigniter controller. /controllers/admin/ dashboard.php content.php enquiries.php /controllers/members/ profile.php
I'm trying to replace a UIViewController root view with a subclassed UIView. In the
I have a view controller hierarchy and the top-most controller is displayed as a
Hey guys, I currently have a root table view which has a toolbar at
In the view controller that has a UITabBarItem, i realized that viewDidLoad() method only
I need to load a UITableViewCell xib into the root controller of a split

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.