Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 918
GLee Avatar asked May 18 '13 02:05

GLee


1 Answers

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

enter image description here

and assuming you are setup something like this

enter image description here

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.

like image 148
Warren Burton Avatar answered Sep 18 '22 18:09

Warren Burton