Search code examples
objective-cuiviewxibsubclassing

Are owners of XIB must/should be UIViewController


I have had success with UIView as owner when I want to subclass UIView with xib.

However, it's kind of awkward and involve moving all superView from self.view to self in initWith:something class.

That's the only function I override and it looks fine enough till now.

So, is owner designed to be only for UIViewController?

Can it be a subclass of UIView too?

What other classes are appropriate?

I am just curious, if there is some tutorial on how to more properly subclass UIView and use XIB?


Solution

  • There's no restriction on which class can act as the File's Owner placeholder. UINib exists specifically to provide you with a way to load nib files with whichever owning object you need.

    See the object loading process for details.