Say I have created an XIB for an icon view. I then want to embed a number of instances of this icon view in a different XIB container view by reference, so if I alter properties / layout in the original icon view XIB, the instances in the container view XIB reflect these changes.
Essentially, embedding by reference.
Maybe I'm being dense, but it seems the default behaviour of Interface Builder when dragging a view into a container view is to copy everything over, rather than referencing the original XIB? And dragging an instance of the class associated with the icon view into the container view just results in a blank view.
I'm sure there's a way to do this, but I'm damned if I can figure it out. I normally avoid IB like the plague ;)
There isn't a way of doing this directly in Interface Builder. I needed to do something similar to this in my last app. What I ended up doing was just placing a placeholder View in the location where you want your referenced xib and then in your viewDidLoad or viewWillAppear, etc, you load that xib and place that loaded view as a child of your placeholder view.
NSArray *views = [[NSBundle mainBundle] loadNibNamed: @"ReferencedView" owner: self options: nil];
UIView *referencedView = (UIView *)[views objectAtIndex:0];
[self.viewPlaceholder addSubview:referencedView];
Alternatively, you can create an IBOutlet in your view controller to hold the referenced view and connect that outlet in IB. If you do, then you won't need to pull the view out of the NSArray.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With