 |
 |
NSTextField Question
|
 |
|
 |
|
Junior Member
Join Date: Dec 2000
Location: Houston, TX, USA
Status:
Offline
|
|
Hello,
I'm new to Cocoa/Obj C, so I'm kind of stuck with the basics. What is the method i use to obtain the value of a text field to use in calculations, etc? Also, what are good references for future questions of this sort? Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
NSTextField inherits from NSControl. There's several methods you can use to get data from your textfield. intValue, doubleValue and floatValue is probably what you're interested in.
Assuming you have the Developer Tools...
HD/Developer/Documentation/Cocoa/Reference/ (ApplicationKit/)
..if not, you can find the same docs on Apple's page somewhere.

|
|
|
| |
|
|
|
 |
|
 |
|
jroepcke
|
|
Originally posted by mikebeam:
Hello,
I'm new to Cocoa/Obj C, so I'm kind of stuck with the basics. What is the method i use to obtain the value of a text field to use in calculations, etc? Also, what are good references for future questions of this sort? Thanks!
I believe this would do the trick (but I don't have OSX handy at the moment:
NSString *myString = [myTextField stringValue];
Check out the Vermont Recipies Cookbook on Stepwise for great sample code and a tutorial.
http://www.stepwise.com/Articles/VermontRecipes/
Jim
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
there are HTML docs way down deep in the frameworks folders
/System/Library/Frameworks/AppKit.framework/Versions/C/Resources/English.lproj/Documentation/Reference/ObjC_classic/Classes/NSTextField.html
and you can also look at the headers in project builder.
What I've found most helpful is searching on the name of an object at OmniGroup dev list archives: http://www.omnigroup.com/search-bin/...ch=NSTextField
tons of good stuff there
|
|
You can take the dude out of So Cal, but you can't take the dude outta the dude, dude!
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2000
Location: Houston, TX, USA
Status:
Offline
|
|
Sounds great! Thanks for the info!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
It's easy to get a value from a text field. If inputField is a pointer to your text field (like you made an outlet in Interface Builder and connected it to the field and that's the name of the outlet) then if you want the number that is in the field, assuming that there is a number there and thingToStoreNumberTo is where you want to store the value from the field, just use:
thingToStoreNumberTo = [inputField floatValue];
If you want to programmatically put a number into the field that's pointed to by inputField then, someNumber being what you want to set it to, you can use:
[inputField setFloatValue:someNumber];
Okay? It gets messier if you start playing with text. Hope that helped.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|