PDA

View Full Version : Setting text in a label to a variable upon button press




Jeremy1026
Jul 18, 2008, 09:26 AM
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,

printf("%i",variable);

So I tried something like that with the SDK knowledge I have and came up with variations of,

(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,

[label setText:@"Words"];

So I know know that my button works.



Jeremy1026
Jul 18, 2008, 09:39 AM
I got it :)

- (IBAction)toOnes {
variable = 3;
label.text = [[NSNumber numberWithInt:variable] stringValue];
}


Then in the .h you have to define the label

IBOutlet UILabel *label;