JMMCalculatorViewController Class Reference
| Inherits from | UIViewController |
| Declared in | JMMCalculatorViewController.h JMMCalculatorViewController.m |
Tasks
UI Elements
-
displayLabelproperty -
buttonViewproperty
Public Properties
-
calculatorproperty
Public Methods
Private Methods
Properties
buttonView
Container view with all of the UIButtons.
@property (weak, nonatomic) IBOutlet UIView *buttonViewDeclared In
JMMCalculatorViewController.hcalculator
The running instance of JMMCalculator to do the heavy lifting.
@property (nonatomic, strong) JMMCalculator *calculatorDeclared In
JMMCalculatorViewController.hInstance Methods
buttonIsAnOperation:
Checks whether title is an operation by comparing it to the JMMCalcOperation
- (BOOL)buttonIsAnOperation:(NSString *)titleParameters
- title
The title of the
UIButtonpressed
Return Value
YES or NO
Declared In
JMMCalculatorViewController.mcalculatorButtonPressed:
Receive calc UIButton tapped and asks handleButtonWithTitlePressed: to take the appropriate action.
- (void)calculatorButtonPressed:(UIButton *)buttonParameters
- button
The
UIButtonthat was tapped
Declared In
JMMCalculatorViewController.hhandleButtonWithTitlePressed:
This method decides which UIButton was tapped and calls the appropriate method.
- (void)handleButtonWithTitlePressed:(NSString *)titleParameters
- title
The title of the
UIButtonpressed. This could be an equal, operation, or numeral button.
Declared In
JMMCalculatorViewController.hhandleEquals
When UIButton tapped is the equals button call [JMMCalculator equate]
and set the text of displayLabel to the result of the calculation.
- (void)handleEqualsDiscussion
Before equating, if no operation was just pressed add the current display text as an operand to the calculator.
Declared In
JMMCalculatorViewController.mhandleNumeralPressed:
When UIButton tapped is a numeral, concatenate numeral to the displayLabel
- (void)handleNumeralPressed:(NSString *)titleParameters
- title
The numeral that was pressed.
Declared In
JMMCalculatorViewController.mhandleOperationPressed:
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 *)titleParameters
- title
Title of the operation that was tapped. Passed in from handleButtonWithTitlePressed:
Declared In
JMMCalculatorViewController.moperationForString:
Translates the NSString representation of an operation to it’s appropriate JMMCalcOperation
- (JMMCalcOperation)operationForString:(NSString *)stringOpParameters
- stringOp
NSStringcalcualtor operation
Return Value
The translated JMMCalcOperation
Discussion
Warning: Division not implemented.
Declared In
JMMCalculatorViewController.msetActionForButtons:
Iterates over given UIButtons and sets their tap action to calculatorButtonPressed:
- (void)setActionForButtons:(NSArray *)buttonsParameters
- buttons
All the buttons
Declared In
JMMCalculatorViewController.hviewDidLoad
On view load, run setActionForButtons: on all buttons in buttonView and intialize a new JMMCalculator
- (void)viewDidLoadDeclared In
JMMCalculatorViewController.m