Binding a toolTip programmatically

Hello,

I have a matrix in which certain cells have their toolTip set to a property. The static setting is working:

I wish to bind the toolTip dynamically to these properties, but:

gives “this class is not key value coding-compliant for the key toolTip.”

It seems strange to me, as the toolTip has a setter, and can be bound in IB. The usual explanation is: I’m doing something wrong, but where?

Regards,

the toObject argument should be your script, so “me”. What is myData? Is it an array or dictionary? I can’t really tell about the withKeyPath argument without knowing more about what they are.

Ric

I replaced the object by “me”.
The cell is a NSButtonCell in a matrix.
The card is a dictionary in a controller array.

I do this in a loop, when the matrix is initialized:

        repeat with theCard in gCardController's arrangedObjects()
            set theCell to (mMap of mRecord)'s cellAtRow_column_(theCard's cMapV,theCard's cMapH)
            theCell's setImage_(NSImage's imageNamed_("Locus"))
--            (mMap of mRecord)'s setToolTip_forCell_(theCard's cName,theCell) -- this works
            theCell's bind_toObject_withKeyPath_options_("toolTip",me,theCard's cName,missing value)
        end repeat

The message says:


What is the meaning of “this class”? NSButtonCell or my script? Does it mean:

“NSButtonCell” cannot be bound by “toolTip”

or

“Your bound property is not valid” ?

Well the whole matrix is bindable for tooltips, but not a single cell, so it seems to me.

Hi SuperMacGuy,

Mmh, I think you’re right: neither NSButtonCell nor its ancestors has a setToolTip: method (or even a toolTip instance variable). Rats. Ok, I’ll do this via the matrix.

Thanks!

I don’t think you’re going to be able to do this with bindings since the matrix itself only has one toolTip. Unless theCard’s cName will be changing often for any particular cell, then using setToolTip_forCell_ will work fine. If you really want to use bindings, then you’d probably need to subclass NSCell to expose a new binding for toolTip. In any case your syntax in the binding statement is still wrong, the keyPath needs to be a string, and if “cName” is a key in theCard, then the forKeyPath argument should be “theCard.cName” (including the quotes).

Ric

Thank you again, Ric, it was just cosmetics. If one day, in a distant future, I meet a user who asks me “Why is the name into the tool tip not updated when I change the name of the card?” I’ll congratulate him for sure :lol:

I keep my working method. I confess I did something not really HIG to make my tool tips more reactive:

but don’t tell the other MacScripters.