Re: Is it possible to define class from interface builder?
Re: Is it possible to define class from interface builder?
- Subject: Re: Is it possible to define class from interface builder?
- From: email@hidden
- Date: Thu, 15 Aug 2013 15:26:18 +0900
On 2013/08/15, at 15:08, Chris Hanson <email@hidden> wrote:
> On Aug 13, 2013, at 11:34 AM, Izak van Langevelde <email@hidden> 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
Wow.
That sounds like a *really* powerful workflow.
Are there any good example code downloads or tutorials that illustrate this well?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden