.Hi,
I have a nib file that contains an header that will be used in most of my views, so that I can change it’s layout just once when I need. I’d like to know if it’s possible to add the header nib view with interface builder, or if I need to do that programmatically and how should it be done.
I’ve thought about setting the subclass of the subview to a UIView subclass that automatically loads the nib file.
- (id)initWithFrame:(CGRect)frame {
UIView *cell;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed: @"MainHeaderView"
owner: self
options: nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass: [UIView class]])
cell = (UIView *) oneObject;
if ((self = [super initWithFrame: [cell frame]])) {
// Initialization code
}
return self;
}
But this also doesn’t seem to work.
Ok, I’ve solved this another way.
I’ve created the headerView and the controller, and a subclass of UIViewController for all views that needed the header to be displayed, loading them all with the header. Something like this:
Every view that needs the header to be there will have a controller that’s a subclass of MyDefaultViewController. Seems to work, although the fact that I don’t specify where to place the header scares me a bit xD