If I create a custom UIView in ChildView.xib - how do I reference that from MainWindow.xib?
I tried to drag a UIView to MainWindow.xib and associate it with the same ChildView class. I made the ChildView.xib's owner a ViewController from the MainWindow.xib and in ChildView.xib, I connected the childView IBOutlet to the view but when I start the app, the view in ChildView.xib doesn't get loaded automatically.
Is this possible? At a basic level, I guess I'm asking how to connect UIViews from separate XIB files to an IBOutlet reference in some other XIB ... like MainWindow.xib.
FWIW, I know how to do this in code (manually instantiating with NSBundle) but in this case, I want to know how to do it completely in IB (Interface Builder).
I experimented with this a bit, and created a NSViewController subclass with an associated XIB file. I could get that loaded automatically by putting an instance of the NSViewController object in the main XIB file, and used the Attributes inspector to set the "Nib name" to the name of the NSViewController subclass's XIB file. That XIB file also contains by default a single view object, which you could customize in IB, or set to a custom view subclass type.
However, it still required one line of code to add the view controller's view to the content view of the main window. (I did this in the delegate)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self.window contentView] addSubview:myVC.view];
}
Further experimentation revealed that having a custom NSViewController subclass wasn't necessary, but you still needed loaded XIB file to be owned by NSViewController.
I didn't see any way to link an outlet in the main XIB to the view object in the loaded XIB. I could only link to the view controller object instead, and then access the custom view via its view property.
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