App int count to text label

Discussion in 'iOS Programming' started by iAppleFan08, Jan 11, 2009.

  1. macrumors newbie

    Joined:
    Aug 26, 2008
    #1
    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.
     
  2. macrumors regular

    xsmasher

    Joined:
    Jul 18, 2008
    #2
    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;
    
     
  3. thread starter macrumors newbie

    Joined:
    Aug 26, 2008
    #3
    Now how do I cross over the same number, count, to another -(IBAction)?
     
  4. macrumors regular

    xsmasher

    Joined:
    Jul 18, 2008
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Aug 26, 2008
  6. thread starter macrumors newbie

    Joined:
    Aug 26, 2008
    #6
    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.
     

Share This Page