I have a MyCustomView subclassed from NSView designed in a .xib.
I would like to insert this view into some of my other xib\'s round my application. How should
Use a view controller as it will handle nib loading for you and provide a place to hook up IBOutlet
and IBActions
in a reusable way.
In your app delegate or whatever controller create an instance of your view controller. Ask your view controller to load its view. Cast the return type to your view class name. Then keep a reference to your view controller and possibly the view.
Tell whatever view to add your view as a subview.
Add any layout constraints.
( you can build out very generic constraints to add themselves in your view or view controller by overriding viewDidMoveToSuperview
or viewDidMoveToWindow
when superview
or window are not nil. Use the same to remove your constraints. )
Oddly you remove a view by telling it to remove itself from its superview
.