• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Binding to a view's model object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Binding to a view's model object


  • Subject: Binding to a view's model object
  • From: Roland King <email@hidden>
  • Date: Sun, 25 Jan 2015 18:34:45 +0800

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


  • Follow-Ups:
    • Re: Binding to a view's model object
      • From: Sandor Szatmari <email@hidden>
    • Re: Binding to a view's model object
      • From: Jonathan Mitchell <email@hidden>
    • Re: Binding to a view's model object
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Trying to create a collection view with evenly distributed cell
  • Next by Date: Re: Binding to a view's model object
  • Previous by thread: Re: Trying to create a collection view with evenly distributed cell
  • Next by thread: Re: Binding to a view's model object
  • Index(es):
    • Date
    • Thread