无法将连接器从 IBOutlet 链接到视图控制器 [英] Can't link connector from IBOutlet to View Controller

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

问题描述

我为视图控制器创建了文件 AViewController.h 和 AViewController.m - 我已将此视图控制器的自定义类设置为 AViewController.

I have created files AViewController.h and AViewController.m, for a view controller - I have set the custom class of this view controller to AViewController.

我在 AViewController.h 中定义了一个对象,它是另一个类 B 的实例:

I have an object defined in AViewController.h, which is an instance of another class B as:

@property (weak, nonatomic) IBOutlet B *object_b;

我希望能够将此 IBOutlet 链接到视图控制器,以便我可以使用它来调用 B 类的函数以在视图控制器上显示内容.但是,我无法做到这一点 - 尝试将一条线从对象拖到视图控制器上没有任何作用.对象旁边没有错误或黄色警告符号.我也尝试从视图控制器到对象执行此操作,并且还从故事板中的菜单尝试了此操作.

I want to be able to link this IBOutlet to the view controller, so that I can use it to call functions of class B to display things on the view controller. However, I'm not able to do this - trying to drag a line from the object to the view controller does nothing. There are no errors or yellow warning symbols next to the object. I tried doing this from the view controller to the object as well, and also tried this from the menu in the storyboard.

我的视图控制器应该重命名为AViewController"吗?我有其他视图控制器,它们的名称与其自定义类不同,并且它们没有任何链接问题.

Should my view controller be renamed to 'AViewController'? I have other view controllers which had names different from their custom classes and they didn't have any linking problems.

我尝试了以下解决方案:XCode 6:无法将任何 IBOutlet 连接到 ViewControllerXcode 6 中的错误 - 视图控制器没有名为(子视图)的插座,但他们没有工作.

I tried solutions from: XCode 6: can't connect any IBOutlet to ViewController and Error in Xcode 6 - view controller does not have an outlet named (subview), but they didn't work.

我使用的是 XCode 6.2

I'm using XCode 6.2

这是一个非常烦人的问题;之前的问题中有一些关于错误报告的讨论,但我不确定是否已解决.感谢您的帮助!

It's a really annoying problem; there was some discussion in the previous questions about a bug report, but I'm not sure if it was solved. Appreciate any help!

推荐答案

只要你的类B"不是视图控制器,这应该很容易.第一步是去你的storyboard或相关的.xib文件,找到对应AViewController"的视图控制器.然后,找到里面有白色方块的黄色小圆圈(视图控制器的顶部)并控制+单击它.您应该会看到一个黑框弹出.(见附图).在框中,应该有一个名为Outlets"的部分.您是否看到下方与您的B"对象相关的一行?如果是这样,则从该线右侧的白色圆圈拖动到视图控制器上代表B"类的对象.这将连接起来.

As long as your class "B" is not a view controller, this should be pretty easy. The first step is to go to your storyboard or related .xib file and find the view controller that corresponds to "AViewController." Then, find the little yellow circle with the white square inside of it (top of view controller) and control+click on that. You should see a black box pop up. (see attached image). In the box, there should be a section called "Outlets." Do you see a line below that related to your "B" object? If so, then drag from the white circle on the right side of that line to the object that represents the "B" class on your view controller. This will wire it up.

如果黑框中没有B"的条目,则视图控制器的设置有问题.

If you do not have an entry for "B" in the black box, then something is wrong with the setup of the view controller.

如果您在黑匣子中有一个B"的条目,但无法将其连接到您的视图控制器,请执行以下步骤:确保您的视图控制器上有一个B"类的对象故事板.如果你不这样做,那就是你的问题.如果你这样做了,但你仍然不能让它工作,你可能需要在故事板中设置对象的类类型.为此,请单击情节提要上的对象,然后在 xcode 中查看右侧面板(下面的屏幕截图 #2).在面板中,单击第三个图标(它看起来像一个小方块).在那里你会看到自定义类".如果在class"下它没有说B",那么这就是你的问题.如果这是您的问题,那么将类设置为B",然后按照我的答案第一段中列出的步骤再次尝试为您的插座接线.

If you have an entry for "B" in the black box, but can't connect it to your view controller, then take the following steps: Make sure you have an object of class "B" on your view controller in the storyboard. If you don't, then that's your problem. If you do, but you still can't get it to work, you probably need to set the class type of the object in the storyboard. To do that, click on the object on the storyboard and look in the right panel in xcode (screen shot #2 below). In the panel, click the 3rd icon over (it looks like a little square). There you will see something that says "custom class." If under "class" it does not say "B", then that's your problem right there. And if that is your problem, then set the class to "B" and then try wiring your outlet again with the steps outlined in the first paragraph of my answer.

这篇关于无法将连接器从 IBOutlet 链接到视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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