I use the Paging-Functionality of the UIScrollView for paging several Views (an array of Views).
ViewController
– View
– ScrollView
My main UIViewController contains a View, inside the View the UIScrollView, which is connected via outlet to my ViewController.h.
I created an xib-File to add a custom View (MyView) to the project; same with the class; i add a subclass of UIView, named MyView. The outlets from MyView.xib I connected to the MyView.h. And changed the Class in MyView.xib from UIView to MyView.
To interact with the MyView.xib out of the ViewController (UIScrollView…), i added a property to ViewController
@property (nonatomic, weak) MyView *myView;
So i’m able to set text, background-color and something else of MyView.
The whole stuff works as it should, but i’m not sure – is it bad-style? So I ask you guys; is that ok what I do, or isn’t it?
It’s actually excellent style.
That’s the point of the class label in IB. Elements were meant to be subclassed, and in doing so, allow for deeper customization than the standard UIKit class has built-in.
Again, a brilliant, but often overlooked aspect. Interface builder outlets were always meant to be weak (or assign), because they are usually maintained by strong top-level objects (say, superviews, or classes). The upside to making it weak is that when your class is deallocated, so are the weak outlets, automatically! See here for some better explanations of why IBOutlets should be weak.