Reputation: 27
I'm new to the Objective-c language. I'm trying to create an app that has a button and a label. The button should display some text which I did already. The only problem is that when I click the button, it only adds the specified text once. I want it to keep adding the same text to the label each I time I press the button.
Here is my .h file
{
IBOutlet UILabel *label;
}
-(IBAction)btnClcik:(id)sender;
Here is the .m file
-(IBAction)btnClcik:(id)sender
{
label.text=@"test";
}
Upvotes: 1
Views: 1416
Reputation:
You need to append to the string?
Then do
label.text = [label.text stringByAppendingFormat:@"%@", textToAdd];
where textToAdd
is a NSString or some other valid object where %@
is the correct format specifier.
Upvotes: 1
Reputation: 62686
To append to the existing text, use the string's concatenation method...
label.text = [label.text stringByAppendingString:@"test"];
Upvotes: 2