Interface Builder won't allow connections to custom UIView class?

Thunk picture Thunk · Feb 17, 2013 · Viewed 8.7k times · Source

Using Xcode 4.3.3, I can't figure out how to connect outlets in a custom UIView class with objects created in Interface Builder.

In one ViewController, I have a variety of buttons, sliders, etc that I'm trying to group into Views. So, within that ViewController in IB, I added 3 views. Only 1 view will be visible at any given time.

I derived custom UIView classes to handle each of these 3 views. My view controller instantiates each of the classes. I selected the view(s) in IB, opened the Identity Inspector and set the Class(es) to my custom class(es). But when I tried dragging connections from the view and/or it's constituent controls to the custom view's .h file IB won't add a connection.

IB allows me to add outlets/actions by dragging to the parent view controller's .h, but not to the custom view's .h file. I thought once I set the View's class to be my custom class, I could drag outlets for the view's components to my custom class rather than in the view controller.

This question seems identical to mine: how to connect UIview outlets to a custom subview The two solutions (manually adding outlets and setting the view's class in IB) did not change the behavior for me. Here are the manual outlets I added:

customView3.h

#import <UIKit/UIKit.h>

@interface customView3 : UIView

@property (retain) IBOutlet customView3 *view3;
@property (retain) IBOutlet UISlider *slider;

@end

customView3.m

#import "customView3.h"

@implementation customView3

@synthesize view3, slider;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    // Initialization code
    }
    return self;
}
@end

What am I missing here? What else do I need to set/check in order to add outlets to my custom UIView rather than the view controller?

Answer

Janene Pappas picture Janene Pappas · Dec 6, 2013

Note that I did get this to work today, but had to insert/type the outlets by hand in the derived class, then I could drag from the header file to the UI element in the Storyboard, but not the other way around.