Re: how to get a double from an NSString
Re: how to get a double from an NSString
- Subject: Re: how to get a double from an NSString
- From: Chris Hanson <email@hidden>
- Date: Mon, 26 May 2008 16:28:09 -0700
On May 26, 2008, at 12:13 PM, Bob Sabiston wrote:
I'm trying to get an NSTableView to be editable, and I am having
trouble getting a numerical value from the supplied object. The
setObjectValue method (?) supplies an argument called aData for the
specific row and column.
The NSTableView data source method is actually named
tableView:setObjectValue:forTableColumn:row:, and is usually written
with a prefix '-' because it's an instance method.
That aData is an NSObject, and an NSString I think. How do I
convert that to a double floating point number?
Actually, the object value is typed as (id) so you can't really assume
anything about it based on the function signature. However, in this
case, you'll be passed the object value of the cell at the specified
table column & row: A table view has one data cell per column, that
can be configured per row, and that cell will have an object value
that is pushed to your data source method as a result of user
interaction.
A cell, in turn, can have a formatter that can convert whatever
representation the user interacts with into whatever object you need
internally. In this case, you could just drop an NSNumberFormatter on
your column in Interface Builder. Instead of getting NSString
instances in your data source method above, you'd get NSNumber
instances - with free support for localized presentation and entry!
-- Chris
_______________________________________________
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