0

I am using UINavigationController's initWithNavigationBarClass:toolbarClass:

to initialize an instance UINavigationController with a Custom Navigation Bar MyCustomNavigationBar.

[super initWithNavigationBarClass:[MyCustomNavigationBar class]
toolbarClass:nil];

I wish to do some setUp of MyCustomNavigationBar in it's initalizer -

e.g.

//  MyCustomNavigationBar.m

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setUp];
    }
    return self;
}

But init is never called. Any ideas?

Ríomhaire
  • 3,084
  • 4
  • 25
  • 40

1 Answers1

0

init is never called in the above code as it is not the "Designated Initializer"

- initWithFrame: is the "Designated Initializer"

Therefore the custom setUp should be done here:

  - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self setUp];
        }
        return self;
    }
Ríomhaire
  • 3,084
  • 4
  • 25
  • 40