I am running XCode 5 with iOS 7. I need to dynamically change the height constraint of a UITextView prior to its layout. I have seen many postings stating that this can be done by making an outlet connection from the constraint in IB to the source code. I am trying to make the connection from the constraint outlet in IB to the header file of the owning class, but am unable to make the connection - IB does not "highlight" when I drag over the header file, as it does when making connections from other objects like buttons etc.
Has anyone encountered this before? All help is greatly appreciated.
Here is a picture of me doing it. I'm control-dragging from the constraint to the header file.
In real life I'm more likely to control-drag to the anonymous category in the implementation file, because I don't want an IBOutlet property to be public. So here's a picture of that too. Sorry, this screen shot does not show the cursor: it is at the bottom end of the stretch line.
You can make an outlet connection by:
Opening the assistant editor and then ctrl+drag your textview to the respective header file. You should see a property created for the textview.
Manually type
@property(nonatomic,retain)IBOutlet UITextField *yourTextField;
.Open the assistant editor, drag from the small empty circle(left to the property) to the corresponding control in your view controller.
If you are still not able to make the connection, clean, save your project and then try again.
Are you trying to create the connection in a UIView class? It seems you can only create a connection in the UIViewController class that is associated with that Scene in your Storyboard.
So your workaround is probably the right thing if you wish to do it from the View itself.
I think I am late for this answer but it still may be worth to write it. I had a similar problem. I hadn't set up the file owner for the view correctly. You can do a simple test using the assistant editor. If the assistant editor doesn't let you pick the automatic selection for the view controller it means that you didn't set up the file owner correctly. Check that the viewcontroller has the same name of the .xib file (that's often the case).
This will let you connect all your IBOutlets, including constraints.
Ok, still can't make the connection to the constraint in IB. However, I worked around the problem by making the text view height constraint a placeholder in IB that I replace with an NSLayoutConstraint that I create in the view's initWithCoder. I maintain a reference to the created constraint and modify its "constant" property as needed.
I'll probably stick with this workaround, but if anyone can help me with the original problem that would be greatly appreciated.
来源:https://stackoverflow.com/questions/22086054/unable-to-make-outlet-connection-to-a-constraint-in-ib