Setting IBOutlet properties on a custom view with a nib

317 Views Asked by At

I have a generic custom view that has a nib file. I subclass this custom view and initialize it like this:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"GenericCustomView"
                                                             owner:self
                                                           options:nil];
        UIView *view = [nibContents objectAtIndex:0];
        [self addSubview:view];
    }
    return self;
}

I want to set some properties on the IBOutlets of the generic view, but if I set them in the initWithFrame method, the IBOutlets in the generic view haven't been loaded yet and are still nil. The awakeFromNib method in the custom view is never called. How can I set the properties of the generic nib files IBOutlets in the custom view class?

I'm only targeting iOS 7.0 and up, using Xcode 5.

0

There are 0 best solutions below