PDA

View Full Version : App int count to text label




iAppleFan08
Jan 11, 2009, 08:11 PM
I am working on an app and I'm still very new so I'm stuck.

I'm trying to get it so that when you press a button two labels are activated. One counts how many chips there are and the other for how much gold there is. There is another button that takes an amount from the chips and adds it to the gold. But there is also a third button that takes away from the chips at set intervals whenever pressed. So I need to know how to manipulate all of this in separate actions while displaying the results of the chips and gold on their labels each time they are changed.



xsmasher
Jan 11, 2009, 11:06 PM
to add or subtract from a number, you can do one of the following, assuming count is an integer or float:


//add
count=count+1;
count++;
//subtract
count=count-1;
count--;


Your label needs a string though - to get the number into a string, use this:


//assumes count is an int
NSString *myText = [NSString stringWithFormat: @"%d", count]
MyLabel.text = mytext;

iAppleFan08
Jan 15, 2009, 09:46 PM
Now how do I cross over the same number, count, to another -(IBAction)?

xsmasher
Jan 16, 2009, 01:24 AM
Now how do I cross over the same number, count, to another -(IBAction)?

I'm not sure I understand the question - but is sounds like a question of variable scope. If you declare the variable inside the IBAction, it only exists for the length of that event. Declare the "count" variable outside the IBAction, and it lasts longer (it has a broader scope.)

You probably want it to be a member variable of your class, so declare it in the .h file. Put it inside the brackets of the @interface section.

iAppleFan08
Jan 16, 2009, 11:05 PM
Ok. Thank you :apple:

iAppleFan08
Jan 18, 2009, 09:51 PM
Now I seem to have another problem... I can't update it. Whenever I try to upload the new file it says that the version is wrong. I changed the version, but I was wondering if I was missing something.