PDA

View Full Version : Obj. C Question




JOD8FY
Feb 26, 2007, 06:52 PM
Hello all,

I have a simple Objective C question. I am trying to create a relatively simple program in Xcode as my first venture with Objective C. I have only programmed with Java in the past. What I want to do is get the text of a text field, convert it to an int (the text in the textfield is a number) then increase that integer by one and convert it back into a string to be displayed in the textfield. In Java, this is what the code would look like:

//grab the integer of the text field, it is a string so we convert it to an integer value
int val=Integer.parseInt(textField.getText());
val++;
//Convert val back to a string and put it back in the value textfield
textField.setText(Integer.toString(val));

What are the commands to do this in Objective C?

Thanks in advance,
JOD8FY :apple:

P.S. - Not sure if this is necessary, but it's programmed in Cocoa.



gamera~
Feb 26, 2007, 07:08 PM
The answer is in the documentation for NSControl (which NSTextField is a subclass of)




int x = [myTextField intValue];
x++;
[myTextField setIntValue:x];

JOD8FY
Feb 26, 2007, 07:41 PM
Thanks a lot. That did the trick!

JOD8FY