Setting text in a label to a variable upon button press

Discussion in 'iPhone/iPad Programming' started by Jeremy1026, Jul 18, 2008.

  1. macrumors 68000

    Joined:
    Nov 3, 2007
    #1
    am trying to display a variable in a label. I don't know how to do it in the SDK though. I know that the normal way to display a variable (in command line Objective-C) is,

    Code:
    printf("%i",variable);
    So I tried something like that with the SDK knowledge I have and came up with variations of,

    Code:
    (IBAction)action {
    variable == 3;
    [label setText:@"%i",variable];
    }
    But it comes back with an error of too many arguments for setText. How do I make it show that variable in the label?
    I am able to get the button to display words using,

    Code:
    [label setText:@"Words"];
    So I know know that my button works.
     
  2. thread starter macrumors 68000

    Joined:
    Nov 3, 2007
    #2
    I got it :)

    Code:
    - (IBAction)toOnes {
    	variable = 3;
    	label.text = [[NSNumber numberWithInt:variable] stringValue];
    }
    
    Then in the .h you have to define the label

    Code:
    	IBOutlet UILabel *label;
    
     

Share This Page