• 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
Re: Simple bindings problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple bindings problem


  • Subject: Re: Simple bindings problem
  • From: mmalc crawford <email@hidden>
  • Date: Sun, 6 Jan 2008 01:58:21 -0800


On Jan 6, 2008, at 12:22 AM, Martin Linklater wrote:
I just thought there may be a way to do it without writing any code

I'm not sure how many times it's been said now, but to reiterate, "Sometimes you have to write some code".

After googling for a bit last night I found this on CocoaDev:

There are a number of ways to customize new objects that get added to the array:


Indeed.
And which you choose depends on where it makes most sense for your particular application. There may be no Right Answer.


Subclass NSArrayController and override newObject or addObject.
Register as an observer of the array's key in the providing object, using KeyValueObserving. You will be informed when a new object is added to that array, which you can then modify (the new object will be passed to you.)
In the object providing the content array, implement the KeyValueCoding array methods, one of which is insertObject:in<Key>AtIndex?:.


Or you could use the straightforward "traditional" way. Connect your Add button to the controller you already have in your nib (typically your File's Owner in a document-based application, otherwise perhaps your App Controller) and put the custom logic in there, just as you always would have...
Your only constraint then is that you add the new object to the array in a KVO-compliant manner -- or add it directly to the array controller.


Well, how do you do it currently?

Currently in my test app I have an NSPopUpMenu, an NSTextField next to it, and two NSButtons (Add and Remove). My NSPopUpMenu is bound to my array controller, which has it's contents initialised in my AppControllers init method. This inits the NSPopUPMenu with 4 strings. I have the Add and Remove buttons triggering the insert: and remove: actions of the array controller.

How do you want to do it?

What I would like is for whatever string I enter into the NSTextField to be used as the string for the new NSPopUpMenu entry.


Presumably your App Controller could have outlets to the text field and the array controller...?
Or you could subclass NSArrayController to add an outlet to the text field...


mmalc

_______________________________________________

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: Simple bindings problem
      • From: Martin Linklater <email@hidden>
References: 
 >Simple bindings problem (From: Martin Linklater <email@hidden>)
 >Re: Simple bindings problem (From: Martin Linklater <email@hidden>)
 >Re: Simple bindings problem (From: Martin Linklater <email@hidden>)
 >Re: Simple bindings problem (From: mmalc crawford <email@hidden>)
 >Re: Simple bindings problem (From: Martin Linklater <email@hidden>)

  • Prev by Date: Re: NSButtonCell in NSTableView doesn't receive setHighlighted:
  • Next by Date: Making undo work with complicated NSTextView subclass
  • Previous by thread: Re: Simple bindings problem
  • Next by thread: Re: Simple bindings problem
  • Index(es):
    • Date
    • Thread