Re: NSTextField getting input number by number
Re: NSTextField getting input number by number
- Subject: Re: NSTextField getting input number by number
- From: "Louis C. Sacha" <email@hidden>
- Date: Sun, 16 Nov 2003 17:27:41 -0800
Hello...
I think what was happening was that the NSTextView was trying to
update itself when you made the
float1 = [textField1 floatValue];
call. It would internally end the editing, convert the string to a
float to validate the input, reset itself to a string made from the
float, and then return the float to you. So, it was causing the
unintentional update of the value internally from "1." back to "1",
loosing the decimal point.
What the other version
float1 = [[[[aNotification userInfo] objectForKey:@"NSFieldEditor"]
string] floatValue];
does is get the string from the NSFieldEditor which is the shared
NSText object that belongs to the window and is used as sort of as a
text input buffer when you edit any type of text field. Since you're
getting the string from that buffer (and then converting it a float),
the NSTextField doesn't even need to know that you are reading the
string, and it doesn't try to update itself. That's probably the
reason why the @"NSFieldEditor" key/object is sent in the
notification's userInfo dictionary, to avoid an unintentional update
of the NSControl (the NSTextField) by allowing you to read from the
buffer directly.
Louis
Althoug I am not sure exactly why this works, the suggestion that you noted
below does work:
float1 = [[[[aNotification userInfo] objectForKey:@"NSFieldEditor"] string]
floatValue];
Thank you to everyone for all of your help and especially louis. You are a
testimate to the helpful nature of the apple community and a great help on
this mailing list.
I will keep everyone updated.
Thanks again,
-jay
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.