Re: NSTextfield value doesn't update binding when set programmatically

  • > I have an NSTextField with a value bound to an NSArrayController. If a
    > user edits the value, everything works OK. But when I try to do the
    > same thing programmatically with
    > [aTextField setValue:aString forKey:@"value"]

    The @"value" is the binding name, not the key. The key is the name of
    your instance variable you've bound to the NSTextField

    NSString * newString // assume this exists
    [aTextField setValue:newString forKey:@"personName"];

    where personName is your ivar.
  • On Jan 11, 2008, at 11:38 AM, Jonathan Dann wrote:

    > The @"value" is the binding name, not the key. The key is the name
    > of your instance variable you've bound to the NSTextField
    > NSString * newString // assume this exists
    > [aTextField setValue:newString forKey:@"personName"];
    > where personName is your ivar.
    >
    No.  Don't do this.  (a) It won't work.  (b) This is not how bindings
    is designed to work.
    This is discussed in the documentation.

    mmalc
  • On 11 Jan 2008, at 19:46, mmalc crawford wrote:

    >
    > On Jan 11, 2008, at 11:38 AM, Jonathan Dann wrote:
    >
    >> The @"value" is the binding name, not the key. The key is the name
    >> of your instance variable you've bound to the NSTextField
    >> NSString * newString // assume this exists
    >> [aTextField setValue:newString forKey:@"personName"];
    >> where personName is your ivar.
    >>
    > No.  Don't do this.  (a) It won't work.  (b) This is not how
    > bindings is designed to work.
    > This is discussed in the documentation.
    >
    > mmalc
    >

    Yeah sorry, I'm too tired so I make embarrassing typos, the ivar in
    you class should be updated programatically by

    [self setValue:newString forKey:@"personName"];

    or self.personName = newValue

    from within your class

    Jonathan
  • > The @"value" is the binding name, not the key. The key is the name
    > of your instance variable you've bound to the NSTextField
    >
    >
    > NSString * newString // assume this exists
    > [aTextField setValue:newString forKey:@"personName"];
    >
    > where personName is your ivar.

    Thank you so much!
    Binding to the corresponding NSArrayController's keypath worked great!
  • On Jan 11, 2008, at 1:27 PM, Damian Terentiev wrote:

    >> NSString * newString // assume this exists
    >> [aTextField setValue:newString forKey:@"personName"];
    >> where personName is your ivar.
    > Thank you so much!
    > Binding to the corresponding NSArrayController's keypath worked great!
    >
    It's not clear what you mean.  The quoted code bears no relation to an
    array controller's keypath...

    mmalc
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today