Re: Problem with NSValueTransformer, NSTableView and NSAttributedString
Re: Problem with NSValueTransformer, NSTableView and NSAttributedString
- Subject: Re: Problem with NSValueTransformer, NSTableView and NSAttributedString
- From: Michael Ash <email@hidden>
- Date: Tue, 23 Jun 2009 00:05:27 -0400
On Mon, Jun 22, 2009 at 11:15 PM, Jerry Krinock<email@hidden> wrote:
>
> On 2009 Jun 21, at 07:37, Donnie Lee wrote:
>
>> I created NSTableView and bind table column with NSTextFieldCell with
>> custom NSValueTransformer subclass to NSArrayController. My value
>> transformer should return NSAttributedString transformed from
>> NSString. Everything works fine except that the table shows NSString
>> instead of NSAttributedString. It looks like: "My text{NSFont =
>> "LucidaGrande....}". How to make the right behavior for my value
>> transformer?
>
> I've never seen an NSTextFieldCell bound to an attributed string. I don't
> believe that NSTextFieldCell supports attributed strings. If you bind it to
> a value that provides an attributed string, it probably extracts the string
> and ignores the attributes, giving the result you see.
>
> As far as I know, an NSTextFieldCell must have the same font for its entire
> string. To set the font, subclass -[NSTableColumn dataCellForRow:] so that
> you can provide the cell. An instance of NSTextFieldCell will be fine. In
> that implementation, send that cell a setFont: message before you return it.
>
> If you really want to have a different font in different attribute runs,
> you'll need to subclass that NSTextFieldCell.
>
> Well, at least someone will probably notice your message now and correct me
> if I'm wrong :)
NSTextFieldCell supports attributed strings just fine. That's why it
has a -setAttributedStringValue: method.
The trouble here is that the table is somehow displaying the
attributed string's description rather than the attributed string
itself. It will probably not be possible to say why this is happening
without seeing Donnie's code.
Even then it may be difficult to say. This sort of problem is why I
dislike using bindings for complicated situations like table views. If
you just set up a simple data source instead, then you can *see*
exactly where all the data is coming from and you can see exactly
what's going out to the table view, and where to alter it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden