无法在Interface Builder(Xcode 5)中创建与子视图的出口连接 [英] Cannot create outlet connections to subviews in Interface Builder (Xcode 5)

查看:147
本文介绍了无法在Interface Builder(Xcode 5)中创建与子视图的出口连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这似乎与其他一些问题重复,但答案对我不起作用。

I know this appears to be a duplicate of some other questions, but the answers are not working for me.


  1. 我创建了单个视图应用。

  2. 在故事板中,我在主视图中添加了一个子视图。

  3. 我的主视图上有一个标签,我的子视图上有另一个标签。

  4. 我创建了一个类型为UIView的类,并将其添加为子视图的自定义类。

  5. 我可以将主视图上的标签拖动到主视图控制器类。但是当我尝试将我的子视图上的标签拖动到我的自定义类时,我无法获得连接。

  6. 我甚至输入了属性信息并尝试手动连接无效。

  1. I have created a single view app.
  2. In the storyboard I added a subview to my main view.
  3. I have a label on my main view and another label on my subview.
  4. I have created a class of type UIView and added it as the custom class for the subview.
  5. I can ctrl-drag my label on my main view to the main view controller class. But when I try to ctrl-drag my label on my subview to my custom class, I cannot get the connection to occur.
  6. I have even typed the property information and tried to make the connection manually to no avail.

最新版本的Xcode Interface Builder中的情况发生了一些变化。有人能告诉我我错过了什么吗?这里几乎没有代码。我只是测试尝试使用自定义类将插座连接到子视图。

Things have changed a bit in the latest version of Xcode's Interface Builder. Can somebody tell me what I am missing? There is literally no code here. I am just testing trying to connect outlets to a subview with a custom class.

第一张图片显示我已经设置了自定义类并添加了属性但是我不能建立连接。

The first image shows that I have set up the custom class and added a property but I cannot make the connection.

第二个图像显示主视图标签已在主视图的控制器中连接。

The second image shows the main view label is connected in the main view's controller.

第三张图片显示子视图标签没有插座连接。

The third image shows that there are no outlet connections for the subview's label.

推荐答案

您可以在 @interface中手动编写 IBOutlet 属性声明的自定义视图子类,假设您已经在IB中定义了子视图的基类,那么您可以从代码中的出口圈拖回到场景中的控件。

You can manually write the IBOutlet property declaration in the @interface of the custom view subclass, and assuming you've defined the base class of your subview in IB, then you can drag from the outlet circle in the code back to the control in the scene.

或者,正如你所指出的,Warren Burton在回答另一个问题时提出了这种技巧和另一种技巧, Can' t在IB中查看子视图

Or, as you point out, Warren Burton suggested both this technique and another in his answer to this other question, Can't Wire to Subview in IB.

这篇关于无法在Interface Builder(Xcode 5)中创建与子视图的出口连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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