How can I configure the Nib load of my subclass of UIScrollView?

I had a nice UIScrollView inside my nib that worked beautifully. Then I had special needs and subclasses of UIScrollView. In my Nib, I changed the class in the identity inspector to my subclass.

But for some reason, my -initWithFrame: method is never called when the nib loader creates all those objects from nib. In fact, I have not changed anything right now in my subclass. And the scroll view just works fine. Expect this to be an empty UIScrollView, even if I said that for testing it should be SpecializedUIScrollView.

Is there anything else I should consider when subclassing a UIScrollView when using a Nib file for its perspective?

My dedicated initializer looks like this:

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        NSLog(@"Hello !!!!!!!!!!!!!");
    }
    return self;
}

Hello , Nib. , , . , Builder.

+3
2

nib xib , , awakeFromNib, init .

+3

initWithCoder, super. setFrame .

initWithFrame initWithCoder, .

- (id)initWithCoder:(NSCoder *)aDecoder {
    [super initWithCoder:aDecoder]; // Required. setFrame will be called during this method.
    return [self initWithFrame:[self frame]];
}
+1

Source: https://habr.com/ru/post/1707879/


All Articles