简体   繁体   English

如何将UIView插座连接到自定义子视图

[英]How to connect UIView outlets to a custom subview

I'm still new to xcode / iOS and have the following problem: 我还是xcode / iOS的新手,有以下问题:

in order to display some mobile debug information, I have a UIview added/connected as outlet-property to one of my Viewcontroller. 为了显示一些移动调试信息,我将一个UIview作为outlet-property添加/连接到我的一个Viewcontroller。 This view is a custom subclass of UIview. 此视图是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). 现在我添加了一些UIlabel作为此视图的子视图,并希望将这些标签的插座连接拖到我的customUIview.h文件中,以便可以将这些标签作为我的自定义UIview类的属性进行访问(无需直接从查看控制器)。

Problem is that the interface builder (I'm using Storyboards/ xcode4.3) does not make the trick. 问题是界面构建器(我使用的是Storyboards / xcode4.3)没有成功。 I can connect the outlets to the ViewControllerClass.h but not to my sub view's .h file. 我可以将插座连接到ViewControllerClass.h,但不能连接到我的子视图的.h文件。 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. 在customview.h文件中手动输入属性插座声明后,我可以将它们从那里按住拖动连接到它们在接口生成器中对应的UIlabel对象。 Works only in this direction! 仅适用于此方向!

Thanks anyway 不管怎么说,还是要谢谢你

Update your custom view class from "UIView" to your "Custom View" class in interface builder. 将自定义视图类从“UIView”更新为界面构建器中的“自定义视图”类。 And now you can make connections just by ctrl+drag your buttons or textfield to your appropriate custom class. 现在,您只需通过按住Ctrl键并将按钮或文本字段拖动到相应的自定义类即可建立连接。

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. 由于三年前一篇有趣的SO帖子(关于连接到UIView的子视图),我发现只是从动作或出口圈(在.h文件中)拖动(不是Ctrl_drag!)到控件,就是这样。 Works perfectly even when the controls are in a different view from the subclassed UIView. 即使控件与子类UIView处于不同的视图中,也能完美地工作。 Works equally well with outlets as with actions though you always drag away from the circle. 虽然你总是拖离圈子,但与行动同样适用于行动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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