Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting constraints programmatically
    primarykey
    data
    text
    <p>I'm experimenting with how to use UIScrollView. After much trouble, I finally got the hang of it. But now I've seem to hit another snag.</p> <p>In this simple app, I have a scroll view with and in order for it to work, I have to set the view's bottom space to scrollview constraint to 0 as described <a href="https://stackoverflow.com/a/15516706/1077789">here</a> and it works fine. I'm doing it through the IB.</p> <p>Now I've come across a scenario where I have to do that part programmatically. I've added the below code in the <code>viewDidLoad</code> method.</p> <pre><code>NSLayoutConstraint *bottomSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; [self.view addConstraint:bottomSpaceConstraint]; </code></pre> <p>But it doesn't seem to work. It outputs the following message in the console window adn i don't know what to make of it.</p> <p><strong>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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "", "" )</strong></p> <p>Can someone please tell me how to do this? I've also attached a demo project <a href="http://www52.zippyshare.com/v/15239751/file.html" rel="nofollow noreferrer">here</a> so that you can get a better idea on the issue.</p> <p><strong>UPDATE:</strong></p> <p>First off thanks for the responses. Using the ways mentioned in the answers I was able to get it working. However ina slightly different scenario its not. Now I'm trying to load a view onto a viewcontroller programatically. </p> <p>If I may explain further. There are 2 view controllers. First one being a <code>UITableViewController</code> and the second one a <code>UIViewController</code>. Inside that a <code>UIScrollView</code>. Also There are multiple <code>UIView</code>s and some of those views' height exceeds the normal height of the screen. </p> <p>The <code>UITableViewController</code> displays a list of options. Based on the user's selection, a particular <code>UIView</code> out of the lot will be loaded into the <code>UIViewController</code> with the <code>UIScrollView</code>.</p> <p>In this scenario, the above method doesn't work. The scrolling isn't happening. Do I have to do something different since I'm loading the view separately?</p> <p>I've uploaded a demo project <a href="http://www72.zippyshare.com/v/15876364/file.html" rel="nofollow noreferrer">here</a> so that you can see it in action. Please see the <code>Email.xib</code> and select <strong>Email</strong> from the table view list.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload