Scared by implicit use of 'description' in bindings
Scared by implicit use of 'description' in bindings
- Subject: Scared by implicit use of 'description' in bindings
- From: Matt Gough <email@hidden>
- Date: Tue, 4 Apr 2006 17:09:21 +0100
One of the first ArrayControllers that I wrote is [still] being used
by the contentValues binding of an NSMatrix to set the titles of a
bunch of button cells. The controllerKey is arrangedObjects and the
model key path is empty.
Originally the objects in the array controller were just strings.
Everything magically worked (I was new to bindings remember) and my
buttons displayed correctly.
As my code evolved I needed to change the underlying objects being
controlled by the array controller to my own object type. In order to
get my buttons to display correctly I found that I needed to write a -
(NSString*) description method in my class. This also worked great,
but I was a little apprehensive at the time as up until then I had
only really used description for debugging purposes. Also, at no
point in my bindings setup do I ever explicitly set 'description' as
the Model Key path. However, I left it alone and carried on with more
important things.
Today I needed to change my buttons so that they displayed an
attributed string instead of a plain string. Just to get it working,
I changed my description method so that it returns an attributed
string instead of a string. Once again it magically worked, but now I
was a little worried. After all, description is supposed to return an
NSString*. The button cell is smart enough to know what to do with
such an return value, but I fear that I am storing up a whole heap of
trouble doing this.
So then I thought - Hey, why not just create a new method
(attributedStringForButtonTitle) in my class and set that as my
Model key path. But when I do this, my button titles end up showing a
portion of the result of calling 'description' on the returned
attributed string! e.g 'LineHeight 0/0' or '-1, HyphenationFactor'.
For now I have reverted back to using an empty Model Key path and
getting my description method to just call
attributedStringForButtonTitle.
Since originally implementing this array controller, I have gone on
to do many others without getting myself as confused as I am now. I
was beginning to think I understood the ins-and-outs of bindings.
What part of the puzzle am I missing?
Or perhaps I am thinking there is a problem when there isn't one.
Any help would be much appreciated.
Matt Gough
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden