Assignment #1 Task #4

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add a new text label (UILabel) to your user-interface which shows everything that has been sent to the brain (separated by spaces). For example, if the user has entered 6.3 Enter 5 + 2 *, this new text label would show6.3 5 + 2 *. A good place to put this label is to make it a thin strip above the display text label. Don’t forget to have the C button clear this too. All of the code for this task should be in your Controller (no changes to your Model are required for this one). You do not have to display an unlimited number of operations and operands, just a reasonable amount.

Create a new label above the number display in the storyboard, change the alignment to “right”, remove its text and create a new outlet called “history”.

Now adjust digitPressed in CalculatorViewController.m by adding

self.history.text = [self.history.text stringByAppendingString:digit];

in the if clause and

self.history.text = [self.history.text stringByAppendingFormat:@" %@", digit];

in the else clause.

Add at the top of enterPressed

if (!self.userIsInTheMiddleOfEnteringANumber)
    self.history.text = [self.history.text stringByAppendingFormat:@" %@", self.display.text];

and at the bottom of operationPressed

self.history.text = [self.history.text stringByAppendingFormat:@" %@", sender.currentTitle];
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.