JMMCalculatorViewController Class Reference
Inherits from | UIViewController |
Declared in | JMMCalculatorViewController.h JMMCalculatorViewController.m |
Tasks
UI Elements
-
displayLabel
property -
buttonView
property
Public Properties
-
calculator
property
Public Methods
Private Methods
Properties
buttonView
Container view with all of the UIButtons
.
@property (weak, nonatomic) IBOutlet UIView *buttonView
Declared In
JMMCalculatorViewController.h
calculator
The running instance of JMMCalculator
to do the heavy lifting.
@property (nonatomic, strong) JMMCalculator *calculator
Declared In
JMMCalculatorViewController.h
Instance Methods
buttonIsAnOperation:
Checks whether title is an operation by comparing it to the JMMCalcOperation
- (BOOL)buttonIsAnOperation:(NSString *)title
Parameters
- title
The title of the
UIButton
pressed
Return Value
YES
or NO
Declared In
JMMCalculatorViewController.m
calculatorButtonPressed:
Receive calc UIButton
tapped and asks handleButtonWithTitlePressed:
to take the appropriate action.
- (void)calculatorButtonPressed:(UIButton *)button
Parameters
- button
The
UIButton
that was tapped
Declared In
JMMCalculatorViewController.h
handleButtonWithTitlePressed:
This method decides which UIButton
was tapped and calls the appropriate method.
- (void)handleButtonWithTitlePressed:(NSString *)title
Parameters
- title
The title of the
UIButton
pressed. This could be an equal, operation, or numeral button.
Declared In
JMMCalculatorViewController.h
handleEquals
When UIButton
tapped is the equals button call [JMMCalculator equate]
and set the text of displayLabel
to the result of the calculation.
- (void)handleEquals
Discussion
Before equating, if no operation was just pressed add the current display text as an operand to the calculator.
Declared In
JMMCalculatorViewController.m
handleNumeralPressed:
When UIButton
tapped is a numeral, concatenate numeral to the displayLabel
- (void)handleNumeralPressed:(NSString *)title
Parameters
- title
The numeral that was pressed.
Declared In
JMMCalculatorViewController.m
handleOperationPressed:
When UIButton
tapped is an operand button, pass the operand to the [JMMCalculator captureOperand:]
and [JMMCalculator captureOperation:] method. This operand will be used later for in the [JMMCalculator equate]
operation.
- (void)handleOperationPressed:(NSString *)title
Parameters
- title
Title of the operation that was tapped. Passed in from handleButtonWithTitlePressed:
Declared In
JMMCalculatorViewController.m
operationForString:
Translates the NSString
representation of an operation to it’s appropriate JMMCalcOperation
- (JMMCalcOperation)operationForString:(NSString *)stringOp
Parameters
- stringOp
NSString
calcualtor operation
Return Value
The translated JMMCalcOperation
Discussion
Warning: Division not implemented.
Declared In
JMMCalculatorViewController.m
setActionForButtons:
Iterates over given UIButton
s and sets their tap action to calculatorButtonPressed:
- (void)setActionForButtons:(NSArray *)buttons
Parameters
- buttons
All the buttons
Declared In
JMMCalculatorViewController.h
viewDidLoad
On view load, run setActionForButtons: on all buttons in buttonView
and intialize a new JMMCalculator
- (void)viewDidLoad
Declared In
JMMCalculatorViewController.m