Bindings & ivars

  • Why, after I have connected a control in my nib. window using bindings can I no longer access it from code?

    After connecting a checkbox control using bindings, when my window controller loads, that control's ivar shows up as nil.

    Thanks,

    Chuck
  • Chuck,

    By "bindings", do you mean "Cocoa Bindings" or a standard IBOutlet?

    If you mean "Cocoa Bindings" using the Bindings Inspector, then your control will only be accessible from code if you have made a standard outlet connection with it. Different types of connections (outlets, actions, bindings, etc) are separate entities. Having one does not mean the others are present. But it is certainly common to have multiple types of connections active for a given object (outlet to a button, action from the button, and binding the button's enabled property, for example).

    Kevin

    On 5 Apr 2010, at 11:53, Charles Burnstagger wrote:

    > Why, after I have connected a control in my nib. window using bindings can I no longer access it from code?
    >
    > After connecting a checkbox control using bindings, when my window controller loads, that control's ivar shows up as nil.
    >
    > Thanks,
    >
    > Chuck
  • Le 5 avr. 2010 à 19:53, Charles Burnstagger a écrit :

    > Why, after I have connected a control in my nib. window using bindings can I no longer access it from code?
    >
    > After connecting a checkbox control using bindings, when my window controller loads, that control's ivar shows up as nil.

    A binding is a mechanism whereby a property of something like a control can be linked to a property of another object. It allows the "observing" object to be updated when the value of the "observed" property changes. It is not meant to be a means of talking to an object in a NIB.

    If you need access to an object in the N IB, then you need to add an IBOutlet to the controller class and hook it up to the appropriate object in the NIB.

    If you want to use the "observer" mechanism of bindings, then you cannot use an ivar in the observed class, you need a KVO compliant property instead, otherwise the notifications of change will not get sent to the observing object.

    Joanna

    --
    Joanna Carter
    Carter Consulting
previous month april 2010 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    
Go to today