• 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: Scared by implicit use of 'description' in bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scared by implicit use of 'description' in bindings


  • Subject: Re: Scared by implicit use of 'description' in bindings
  • From: Matt Gough <email@hidden>
  • Date: Tue, 4 Apr 2006 17:40:34 +0100


On 4 Apr 2006, at 17:18, Paul Lynch wrote:

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.

At some point you bound something (presumably your button title) to the object itself (selectedObject, or whatever). It will call the description method to 'coerce' it to a string - this is what you have missed. Change that binding to your buttonTitle method.


Alas, AFAIK there is no such binding hiding out anywhere.


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.

At least you knew it :-).

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'.

I didn't think buttons could take attributed strings as titles, just plain strings. I could be wrong, but I'm too lazy to look it up. If I'm right, you need to use an NSString.



setAttributedTitle on NSButton and NSButtonCell.

Thanks for trying

Matt
_______________________________________________
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


  • Follow-Ups:
    • Re: Scared by implicit use of 'description' in bindings
      • From: "Shawn Erickson" <email@hidden>
References: 
 >Scared by implicit use of 'description' in bindings (From: Matt Gough <email@hidden>)
 >Re: Scared by implicit use of 'description' in bindings (From: Paul Lynch <email@hidden>)

  • Prev by Date: trying to add Growl support
  • Next by Date: Faceless Background Applications
  • Previous by thread: Re: Scared by implicit use of 'description' in bindings
  • Next by thread: Re: Scared by implicit use of 'description' in bindings
  • Index(es):
    • Date
    • Thread