简体   繁体   中英

Can't Wire to Subview in IB

Quick question. Using IB, I have a subview in a ViewController. In that subview I have a label, which I would like to wire to my custom subview class. However, IB will not let me. What am I missing?

I also tried to add the label programmatically; however, it appears that the frame was not ever set. I could hard code the size of the label, but I could not make it dependent on the frame size of my subview, because the frame and the bounds were always zero rects, even after the view showed up in my view controller at a non zero size. Any ideas here would also be much appreciated.

You are actually completely right. It wont let you connect from IB to the Header of a custom view in Xcode 4.6.2

Personally I would file a Radar but I would want to do a bit more research to prove it and as this is a pattern I wouldn't ever use then I won't.

Fortunately you can get around it

Make sure your custom view is configured correctly in IB

在此输入图像描述

and assuming you are setup something like this

在此输入图像描述

Then you can manually declare in your header

@interface MyCustomView : UIView

@property (weak) IBOutlet UILabel *label;

@end

And drag FROM the dot that appears beside the property TO the label.

Or drag FROM the right-click HUD of the custom view TO the label.

Neither case will work by dragging from the label to the view.

在头文件中,您需要将标签定义为IBOutlet ,然后您可以从文件所有者拖动到标签。

IBOutlet * lblSomeLabel;

禁用AutoLayOut并重试。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM