Cannot create outlet connections to subviews in Interface Builder (Xcode 5)

IosObjective CUiviewXcode5

Ios Problem Overview


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

  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.

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.

Main view and subview in Interface Builder - custom class is set

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

Main view and subview in Interface Builder - main view's label is connected

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

Main view and subview in Interface Builder - cannot connect subview's label

Ios Solutions


Solution 1 - Ios

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.

enter image description here

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.

Solution 2 - Ios

The issue has to do with the File Owner of the View Controller. It is probably set up as being IOViewController, thus you can only make property connections in that .h file.

What you can do, is create another .nib file for the subview and put the subview in there. Then in that .nib file, make the file owner IOSubview. Property connections will work just fine there. Then just add the subview to your IOViewController programatically. Just remember to load the nib file from bundle first.

Solution 3 - Ios

This is what I did (in Swift):

  • I Created a new ViewController (e.g. class MyViewController: UIViewController {})
  • In StoryBoard, I expanded the 'Scenes' (i.e. the tree view of all UI components) and selected 'MyViewController'
  • Using the 'identity inspector' I assigned the 'MyViewController' class (as oppose to the default UIViewController)

After that I was able to assign an action.

I suspect that for Obj-C it is similar process.

Solution 4 - Ios

You don't create outlets in the subclass, you create the outlet on the view controller it is on. You need to #import the subclass into IDViewController.h and create an outlet there.

IDViewController.h

#import "IDSubclass.h"
...
@property (strong, nonatomic) IBOutlet IDSubclass *outletName;

Solution 5 - Ios

Zoom your storyboard to 100%. If you zoom out, to say 50%, then the outlet connection won't work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPatriciaView Question on Stackoverflow
Solution 1 - IosRobView Answer on Stackoverflow
Solution 2 - IosChoppin BroccoliView Answer on Stackoverflow
Solution 3 - IoszevijView Answer on Stackoverflow
Solution 4 - IosJosue EspinosaView Answer on Stackoverflow
Solution 5 - IosMakkuView Answer on Stackoverflow