I’ve made my own keyboard with some buttons made A-Z button and gave them Titles A button has title A, B button has title B and so on.
I added a label so when I click a button it would display the title of that button and it does.
When I click A it displays A, when I click B it displays B. The problem is that I want them to display next to each other but I can’t get it work. like when I press ABC it would display ABC not first A then replace it with B and then replace it with C, because that is what it does now.
-(IBAction) clicked: (id)sender{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newLabelText = [[NSString alloc] initWithFormat:@"%@", titleOfButton];
labelsText.text = newLabelText;
}
Here is some code from a calculator where it does work but I can’t find the right way to implant it with my code
//-(IBAction)buttonDigitPressed:(id)sender {
//currentNumber = currentNumber*10 + (float)[sender tag];
//calculatorScreen.text = [NSString stringWithFormat:@"%2f",currentNumber];
//}
is there any1 who can tell me how to get this working or knows an entire other way to get it working i’ve been looking and trying for almost a full week now thanks
This is the line that is causing you problems:
You are setting the label text to be ONLY newLabelText. What you want to do is concatenate the strings, which will combine the old text with the new text. This one change should do it: