Re: Binding to a view's model object
Re: Binding to a view's model object
- Subject: Re: Binding to a view's model object
- From: Sandor Szatmari <email@hidden>
- Date: Sun, 25 Jan 2015 10:46:38 -0500
I think you can bring an object controller into your xib from the IB pallet. Bind the content object of the controller to your NSView subclass and expose the binding of modelObject.someStringProperty through the object controller's attributes inspector panel. The all your subviews will bind to the object controller. This assumes you can make your NSView visible in IB through an NSObject IB widget. Typically, I would have the model in a controller object or delegate object which are more common to materialize in the xib.
Sandor Szatmari
> On Jan 25, 2015, at 05:34, Roland King <email@hidden> wrote:
>
> I have a xib with a top-level view and a bunch of subviews which represents one view of a given model object. The top-level NSView subclass has a readwrite property which is the model object of which it's a view. I thought this was a pretty standard pattern, especially in OSX which only just recently started to really make use of view controllers.
>
> Many of the subviews just show strings and other values from the model object, and some of them allow editing as well. So what I wanted to do is use bindings to bind modelObject.someStringProperty to the value of one of the text fields, for instance. Doing that would take care of 90% of the easy properties on the model, leaving just a few I'd need to hand-code. However IB doesn't let me make bindings to a property of the top-level view. I can bind to files owner, the shared defaults controller and the application only, or to any other standalone Object I put in the NIB, but none of those help.
>
> The view in this case is going in a stack view, which wants an NSView. I thought about moving the logic into a view controller which could be the Files Owner, but I would have then to separately retain those view controllers as their views don't retain them and the stackview just wants the view, so that feels a little clunky. The views are meant to be reusable, hence the single readwrite model object property on the view.
>
> Is there a way to do these bindings? Can it be done in IB if so or do I need to call bind:toObject:withKeyPath:options: Is there some other object I could put in the NIB which would intermediate this for me?
> _______________________________________________
>
> 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
_______________________________________________
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