简体   繁体   中英

How to connect UIView outlets to a custom subview

I'm still new to xcode / iOS and have the following problem:

in order to display some mobile debug information, I have a UIview added/connected as outlet-property to one of my Viewcontroller. This view is a custom subclass of UIview. Now I addeddd some UIlabels as sub views to this view and want to drag the outlet connections from these labels to my customUIview.h file in order to have these labels accessible as properties of my custom UIview class (no need to access them directly from the view Controller).

Problem is that the interface builder (I'm using Storyboards/ xcode4.3) does not make the trick. I can connect the outlets to the ViewControllerClass.h but not to my sub view's .h file. Can anyone point out where the problem is?

Just solved the problem. After typing the property outlet declarations manually in the customview.h file I could ctrl-drag-connect them from there to their corresponding UIlabel objects in the interfacebuilder. Works only in this direction!

Thanks anyway

Update your custom view class from "UIView" to your "Custom View" class in interface builder. And now you can make connections just by ctrl+drag your buttons or textfield to your appropriate custom class.

Problem solved! Due to an interesting SO post from three years ago (about connecting to subviews of UIView), I discovered that one merely drags (not Ctrl_drag!) from the action or outlet circle (in the .h file) to the control and that's it. Works perfectly even when the controls are in a different view from the subclassed UIView. Works equally well with outlets as with actions though you always drag away from the circle.

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