• 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: Can initialKey & initialValue be set via bindings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can initialKey & initialValue be set via bindings?


  • Subject: Re: Can initialKey & initialValue be set via bindings?
  • From: John Chacho <email@hidden>
  • Date: Thu, 16 Jun 2016 23:41:19 +0530

I should have been more clear, the new entries are simple key-value pairs
where the values are simple strings.

Your reply helped me understand some of my confusion, but not before I had
tried a few crazy ideas and received embarrassing exceptions like:

initValue[6961:329407] [<AppController >
addObserver:<NSObjectParameterBinder >
forKeyPath:@"<some foolish text from IB Initial Value field>"
options:0 context:0x6000000e4500] was sent to an object that is not
KVC-compliant for the "<something equally embarrassing>" property.

and

-[NSTextField copyWithZone:]: unrecognized selector sent to instance

After revisiting the KVC and KVO documentation, working on something else
and forcing myself to not think about the seemingly trivial problem...
What I hope is a safe, simple and non-memory-leaky solution popped into
focus:

1. Declare and synthesize two properties to hold a key NSString and a value
NSString in the controller.
2. Bind the NSTextFields to the properties and check "Continuously Updates
Values"
3. Bind the NSDictionaryControl "Initial Key" and "Initial Value" to the
properties.

PS: Another factor that may have muddied the water for me was not
Command-S'ing to save my hasty, fool-hearty and something angry XIB and
other file updates before compiling and running.



On Thu, Jun 16, 2016 at 2:40 PM, Quincey Morris <
email@hidden> wrote:

> On Jun 15, 2016, at 21:23 , John Chacho <email@hidden> wrote:
>
>
> If not, how can I add an arbitrary new record into the dictionary?
>
>
> If I understand correctly, you have to go the long way round for this
> scenario (which is not specific to NSDictionaryController). Instead of
> connecting your Add button to the standard “add:” action of the
> NS…Controller, you must instead create a custom action method, e.g.
> ‘addEntry:’. In this method, you’ll need to get hold of the current
> selection (if that’s where the "based on” values come from), verify that
> it’s suitable for creating a new entry, create the entry, then add the new
> entry to your data model dictionary KVO compliantly — or use the
> NS…Controller’s ‘addObject:’ method, which causes a KVO compliant update.
> (Both ways are equally easy for an underlying NSDictionary, since it
> provides KVO compliance for free, but it can be slightly harder for other
> underlying collection types.)
>
> In effect, the above is exactly what the ‘add:’ action method does, except
> that it can’t customize the data model object it creates to add.
>
>
_______________________________________________

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: Can initialKey & initialValue be set via bindings?
      • From: Quincey Morris <email@hidden>
References: 
 >Can initialKey & initialValue be set via bindings? (From: John Chacho <email@hidden>)
 >Re: Can initialKey & initialValue be set via bindings? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Selected value binding in popups
  • Next by Date: Re: Selected value binding in popups
  • Previous by thread: Re: Can initialKey & initialValue be set via bindings?
  • Next by thread: Re: Can initialKey & initialValue be set via bindings?
  • Index(es):
    • Date
    • Thread