My goal is, to have a subclassed UIView
(lets call it infoView
) designed in his own XIB so that I can present it in many UIViewController
's.
The Problem:
So far, when I was adding UIView
's to a UIViewController
I always had to make an UIViewController
the file's owner of the UIView
's .xib file to load the view with something like:
...
//this is inside the calling UIViewController's method
// InfoView *infoView is ivar and a subclass of UIView
infoView = nil;
NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"InfoView"
owner:self options:nil];
for (id object in bundle) {
if ([object isKindOfClass:[InfoView class]])
infoView = (InfoView *)object;
}
[[self view] addSubview:infoView];
...
But I want to use the same UIView
in many different UIViewController
's, so I actually don't want a file's owner except maybe the class itself. In ThomasM's question he was setting the UIView
itself to be the file's owner but without success.
In the answers there I found a solution to set the file's owner to nil. To do so I had to add all calling UIViewController
objects from the Interface Builder object library to the InfoView.xib file and connect them with their infoView
outlets.
But this doesn't feel right. So here I would like to collect solutions to
encapsulate a UIView
together with his xib-file to use it in many different view controllers. How do you guys handle that?
Thx for any help.
EDIT:
The infoView
is something like an overlay which appears when the user presses a button on one of the view controllers. It's NOT the View controllers "main" view. It gives detailed informations about the view of his superviews view controller and will disappear afterwards. I only fill the infoView
with different contents threw out all the calling view controllers.