Search code examples
objective-ciosuiscrollviewinterface-buildersubclassing

Subclassing in IB


I have UIScrollView added to the main window of the app with IB. What I want is that view to subclass UICustomScrollView instead of UIScrollView. To do that I choose the UIScrollView and then I change Custom class to UICustomScrollView in identity inspector. I have put some NSLog messages in init method of UICustomScrollView. When I run the app UICustomScrollView seem like it is not used because NSLog messages in init are not printed.

What I miss here ?


Solution

  • Here's what the UIView Class Reference has to say about initWithFrame::

    If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file.

    If your NSLog is only in initWithFrame, it won't be called if the view is loaded from a nib.