无法在IB中连接到子视图 [英] Can't Wire to Subview in IB

查看:64
本文介绍了无法在IB中连接到子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问。使用IB,我在ViewController中有一个子视图。在该子视图中,我有一个标签,我想将其连接到我的自定义子视图类。但是,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.

推荐答案

你其实是完全正确的。它不会让你从IB连接到Xcode 4.6.2中的自定义视图的标题

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.

幸运的是你可以绕过它

确保您的自定义视图在IB中正确配置

Make sure your custom view is configured correctly in IB

并假设您设置的内容为

然后你可以手动申报在你的标题中

Then you can manually declare in your header

@interface MyCustomView : UIView

@property (weak) IBOutlet UILabel *label;

@end

并拖动 FROM 出现在 TO 标签旁边的点。

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

或拖动 FROM 右键单击自定义视图 TO 标签的HUD。

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.

这篇关于无法在IB中连接到子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆