Re: Editing a dictionary using NSTableView
Re: Editing a dictionary using NSTableView
- Subject: Re: Editing a dictionary using NSTableView
- From: Corbin Dunn <email@hidden>
- Date: Mon, 27 Oct 2008 09:27:00 -0700
On Oct 26, 2008, at 3:29 PM, Graham Cox wrote:
Let's say I have a NS(Mutable)Dictionary and I'd like to make a very
simple editor for its keys and values. So I have a NSTableView with
two columns, key and value. The dictionary can contain any mix of
strings and numbers, and the numbers can be ints or reals.
I find that when setting an edited value for a given key, everything
gets converted to a string, because the object type returned by the
table is a string. (The column type for value is a string, but
numbers passed as the object value are automatically converted. I'm
not using a formatter.)
That's right; setObjectValue: on a text cell will ultimately make it
into a string that can be displayed and edited by the user.
Is there a simple way to allow the table to edit a value but
preserve its type in the dictionary?
You probably want to set an appropriate formatter on the cell in -
willDisplayCell:. This sounds like the best approach to what you are
wanting. You could always right a custom formatter if you need to.
corbin
I could check the type of the key I'm about to set and convert each
value to that type, but it seems very clunky. I feel I've missed
something obvious.
_______________________________________________
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