Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTextField Question

NSTextField Question
Thread Tools
Junior Member
Join Date: Dec 2000
Location: Houston, TX, USA
Status: Offline
Reply With Quote
Dec 22, 2000, 10:05 PM
 
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
Reply With Quote
Dec 23, 2000, 01:48 AM
 
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
Guest
Status:
Reply With Quote
Dec 23, 2000, 01:52 AM
 
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
Reply With Quote
Dec 23, 2000, 06:35 AM
 
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
Reply With Quote
Dec 23, 2000, 10:44 AM
 
Sounds great! Thanks for the info!
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Dec 25, 2000, 11:12 AM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2