Assignment #1 Extra Task #2

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

When the user hits an operation button, put an = on the end of the text label that is showing what was sent to the brain (required task #4). Thus the user will be able to tell whether the number in the Calculator’s display is the result of a calculation or a number that the user has just entered.

Basically we add an equal sign in operationPressed:

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

but have to remove it again fur further entries. We can do this using a helper function

- (void)removeEqualSignFromHistory;
    NSRange range = [self.history.text rangeOfString:@"="];
    if (range.location == NSNotFound) return;
    NSString *history = [self.history.text copy];
    self.history.text = [history substringToIndex:([history length] - 2)];        

which we call every time we need to (before changing the history):

[self removeEqualSignFromHistory];

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *