NadavRub
NadavRub

Reputation: 2610

Custom 'XiB' Based UI Control

I am trying to implement a custom view ( C# Custom UserControl equivalent )

Use-case:

  1. I have implemented a custom UIView based control
  2. The Control is associated with a specialized XiB file ( Xib file A )
  3. The 'File's Owner' of the XiB is a specialized class where IBOutlets are defined
  4. This control is referred to by a different XiB file ( XiB file B )

I was expecting Xib file A elements to be rendered within Xib file B, however, The UI wasn't presented although all IBOutlets were properly associated, and 'awakeFromNib' was called.

What am I doing wrong here ?

The following is the code for the cusom XiB based ~control~ ( which is referred to by another control/view of a different XiB)

@interface SeriesView ()
@property (strong, atomic, readonly) MediaViewer* mediaViewer;
- (void) OnInitialize;
- (void) awakeFromNib;
@end

@implementation SeriesView

@synthesize mediaViewer = _mediaViewer;
@synthesize image = _image;
@synthesize scroll = _scroll;

- (id)initWithFrame:(CGRect)frame
{
    if(nil == (self = [super initWithFrame:frame]))
        return nil;
    [[NSBundle mainBundle] loadNibNamed:@"SeriesView" owner:self options:nil];
    return self;
}

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(nil == (self = [super initWithCoder:aDecoder]))
        return nil;
    [[NSBundle mainBundle] loadNibNamed:@"SeriesView" owner:self options:nil];
    return self;
}

- (void) OnInitialize
{
    _mediaViewer = [[MediaViewer alloc] init];
    _image.hidden= NO;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self OnInitialize];    
}
@end

Upvotes: 0

Views: 3565

Answers (1)

NadavRub
NadavRub

Reputation: 2610

Per: UIView and initWithFrame and a NIB file. How can i get the NIB file loaded?

The only part missing was

  1. adding a view outlet to my custom view
  2. Associating the view with the corresponding root view @ the XiB
  3. calling '[self addSubview:self.view]' through awakeFromNib

Upvotes: 2

Related Questions