You should not be setting the class of your view controller to be a subclass of UIView
in Interface Builder. That is most definitely at least part of your problem. Leave that as either UIViewController
, some subclass of it, or some other custom class you have.
As for loading only a view from a xib, I was under the assumption that you had to have some sort of view controller (even if it doesn't extend UIViewController
, which may be too heavyweight for your needs) set as the File's Owner in Interface Builder if you want to use it to define your interface. I did a little research to confirm this as well. This is because otherwise there would be no way to access any of the interface elements in the UIView
, nor would there be a way to have your own methods in code be triggered by events.
If you use a UIViewController
as your File's Owner for your views, you can just use initWithNibName:bundle:
to load it and get the view controller object back. In IB, make sure you set the view
outlet to the view with your interface in the xib. If you use some other type of object as your File's Owner, you'll need to use NSBundle
's loadNibNamed:owner:options:
method to load the nib, passing an instance of File's Owner to the method. All its properties will be set properly according to the outlets you define in IB.