Unable to make outlet connection to a constraint in IB

不打扰是莪最后的温柔 提交于 2019-11-26 18:55:29

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:

  1. Opening the assistant editor and then ctrl+drag your textview to the respective header file. You should see a property created for the textview.

  2. 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.

johnnyspo

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!