Hello Patric.

I was able to get the NSFormatter subclass to work properly by ignoring all 
non-Foo objects sent to it. The Cocoa docs are indeed lacking in this respect 
as there is no mentioning that the cell's title will first be sent. To me this 
feels a bit odd anyway since I can think of no reason why should the 
NSFormatter be concerned about it.

Subclassing an NSCell class seemed to me a bit overcomplicated for this task so 
I am going with the NSFormatter. Thanks for the suggestion though.

On Jan 3, 2010, at 1:58 PM, Patrick Mau wrote:

> Hallo Henri
> 
> Your assumption about how formatters should work are correct. To provide a 
> useful answer
> I have setup a mini project here, because I have stumbled over a detail I did 
> not now:
> 
> http://public.me.com/pmau
> 
> I took your approach and implemted a minimal datasource and a "Foo" object.
> This is not a great example, but here's what II did not know:
> 
> When you wire up the formatter to the text field cell in IB,
> "setFormatter" is called on the TextFieldCell, which in turn will
> call your formatting code withe the cell's title:
> 
> run
> [Switching to process 7123]
> Running…
> 2010-01-03 12:39:47.790 Formatter[7123:a0f] NSCFString Cell Title
> 2010-01-03 12:39:47.810 Formatter[7123:a0f] Foo <Foo: 0x1139291d0>
> 2010-01-03 12:39:47.811 Formatter[7123:a0f] Foo <Foo: 0x1151000a0>
> 2010-01-03 12:39:47.811 Formatter[7123:a0f] Foo <Foo: 0x1151000b0>
> 
> Therefore you have too prepare to receive at least one object, which is not 
> "Foo".
> 
> Interestingly, I could not find that little detail in the documentation.
> 
> If you want to return an instance Foo from your datasource, it is much more 
> convenient to write
> your own NSCell subclass, because you can control editing and formatting much 
> easier.
> You can even use an attached formatter that you setup in IB, passing it a 
> property of Foo.
> 
> All the best,
> Patrick

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to