No, you a asking about referencing nibs from other nibs. There are ways to achieve this with some awakeAfterUsingCoder:
hacks or something like that. Usually you check if view has no subviews and load view from nib then or create some IB-dummy class that replaces itself with target class after it get's loaded. All this techniques have issues, so I'd recommend against them.
So I'd suggest loading it from code, nice catch would be to use view controller containment.
There's something really cool, appeared relatively not long ago: IBDesignable and IBInspectable, it had to appear at some point.
One example would be some temporary code I used while required framework was not yet ready (It's an UIButton dummy IB subclass):
//
// That's just an example, do not use it in production code
//
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder
{
UIButton *buttonMain = // create button, which will replace button of dummy class from nib
buttonMain.translatesAutoresizingMaskIntoConstraints = NO;
// copy internal constraints
[self copyInternalConstraintsToView:buttonMain];
// set titles
NSString *title = [self titleForState:UIControlStateNormal];
[buttonMain setTitle:title forState:UIControlStateNormal];
title = [self titleForState:UIControlStateHighlighted];
[buttonMain setTitle:title forState:UIControlStateHighlighted];
title = [self titleForState:UIControlStateDisabled];
[buttonMain setTitle:title forState:UIControlStateDisabled];
title = [self titleForState:UIControlStateSelected];
[buttonMain setTitle:title forState:UIControlStateSelected];
return buttonMain;
}
/**
* Used only in awakeAfterUsingCoder, as self has only internal constraints at that moment.
* If you'll try to use it somewhere else, behavior is undefined.
*
* This method is straightforward and could not suit everybody's needs.
*
* %Comments edited%
*
* @param replacementView view to add constraints to
*/
- (void)copyInternalConstraintsToView:(UIView *)replacementView
{
for (NSLayoutConstraint* constraint in self.constraints)
{
if([constraint isMemberOfClass:[NSLayoutConstraint class]])
{
id first = constraint.firstItem;
id second = constraint.secondItem;
id newFirst = first;
id newSecond = second;
BOOL match = NO;
if (first == self)
{
newFirst = replacementView;
match = YES;
}
if (second == self)
{
newSecond = replacementView;
match = YES;
}
// constraints to subviews from recource are not supported
if(newFirst != nil && newFirst != replacementView)
{
match = NO;
}
if(newSecond != nil && newSecond != replacementView)
{
match = NO;
}
if (match)
{
@try
{
NSLayoutConstraint* newConstraint = nil;
newConstraint = [NSLayoutConstraint constraintWithItem:newFirst
attribute:constraint.firstAttribute
relatedBy:constraint.relation
toItem:newSecond
attribute:constraint.secondAttribute
multiplier:constraint.multiplier
constant:constraint.constant];
newConstraint.shouldBeArchived = constraint.shouldBeArchived;
newConstraint.priority = constraint.priority;
[replacementView addConstraint:newConstraint];
}
@catch (NSException *exception)
{
NSLog(@"Constraint exception: %@\nFor constraint: %@", exception, constraint);
}
}
}
}
}
Some links:
Embedding custom-view Nibs in another Nib: Towards the holy grail, An Update on Nested Nib Loading