On Aug 13, 2013, at 11:34 AM, Izak van Langevelde <eezac...@xs4all.nl> wrote:

> A user interface contains several instances of a specific form, which is 
> easily created in Interface Builder.
> Is there any way to derive a subclass of NSView from this form, so that it 
> can be reused?

A good way to do this is to create a xib that has an NSView with your form all 
laid out. Then use the Inspector to set File’s Owner’s class to 
NSViewController; File’s Owner will get a “view” outlet as a result of that. 
Then just connect that “view” outlet to your view.

That will get you a reusable NSViewController you can instantiate using 
-[NSViewController initWithNibName:bundle:] any number of times in your 
application, and you can thus substitute its view into your app at any place 
you like.

You could also create an NSView subclass, call it a “ViewControllerHostView,” 
that knows how to embed a view controller’s view within itself based on a User 
Defined Runtime Attribute you set up in Interface Builder.[1]

That way your ViewControllerHostView can have a controllerNibName property that 
gets set when it’s instantiated at load time; it can then, when it’s actually 
being presented, also load the view controller from the named nib and embed its 
view within itself.

  -- Chris

[1] User Defined Runtime Attributes are values set in Interface Builder that 
then get set on your objects via KVC when a nib file is loaded. They work in OS 
X 10.6 and iOS 5 and later.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to