iOS Dev – Assignment #2 – Extra Task

Add a memo-function to store a number

Start my rearranging the buttons to make space for three new ones:

iOS Dev – Assignment #2 - Extra Task – Additional Buttons
iOS Dev – Assignment #2 – Extra Task – Additional Buttons

Create a variable to store the value:

float numberInMemory;

Initialize it:

- (void)viewDidLoad
{
    ...
    numberInMemory = 0;
}

And connect the buttons to suitable methods:

- (IBAction)addMemoryButtonPressed:(UIButton *)sender {
    numberInMemory += [self.numberTextField.text floatValue];
}

- (IBAction)subtractMemoryButtonPresed:(UIButton *)sender {
    numberInMemory -= [self.numberTextField.text floatValue];
}

- (IBAction)getMemoryButtonPressed:(UIButton *)sender {
     self.numberTextField.text = [NSString stringWithFormat:@"%@", [NSNumber numberWithFloat:numberInMemory]];
}
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.