Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iAppleFan08

macrumors newbie
Original poster
Aug 26, 2008
25
0
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

macrumors regular
Jul 18, 2008
140
0
to add or subtract from a number, you can do one of the following, assuming count is an integer or float:

Code:
//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:

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

xsmasher

macrumors regular
Jul 18, 2008
140
0
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

macrumors newbie
Original poster
Aug 26, 2008
25
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.