Can't link connector from IBOutlet to View Con

2019-09-05 04:47发布

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.

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

@property (weak, nonatomic) IBOutlet B *object_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.

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.

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.

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!

1条回答
走好不送
2楼-- · 2019-09-05 05:43

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.

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

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.

enter image description here

enter image description here

查看更多
登录 后发表回答