Commits

Jay Yu  committed 1e83b23

finished Undo button

  • Participants
  • Parent commits 3723472

Comments (0)

Files changed (4)

File Calculator/CalculatorBrain.h

 - (void)pushVariable:(NSString *)variable;
 - (double)performOperation:(NSString *)operation;
 - (void)clearStates;
+- (void)removeTopItemFromProgram;
 
 // New in Assignment 2
 @property (readonly) id program;

File Calculator/CalculatorBrain.m

     [self.programStack removeAllObjects];
 }
 
+- (void)removeTopItemFromProgram
+{
+    id topOfStack = [self.programStack lastObject];
+    if (topOfStack) {
+        [self.programStack removeLastObject];
+    }
+}
+
 + (double)runProgram:(id)program
  usingVariableValues:(NSDictionary *)variableValues
 {

File Calculator/CalculatorViewController.m

 
 - (IBAction)undoPressed
 {
+    if (! self.userIsInTheMiddleOfEnteringANumber) {
+        [self.brain removeTopItemFromProgram];
+    }
+
     if (self.userIsInTheMiddleOfEnteringANumber) {
         [self backspacePressed];
     }
+
     if (! self.userIsInTheMiddleOfEnteringANumber) {
-
+        [self updateDisplays];
     }
 }
 

File Calculator/en.lproj/MainStoryboard.storyboard

                                     <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 </state>
                                 <connections>
-                                    <action selector="undoPressed:" destination="2" eventType="touchUpInside" id="WNX-hf-4ER"/>
+                                    <action selector="undoPressed" destination="2" eventType="touchUpInside" id="M3A-Vr-EIM"/>
                                 </connections>
                             </button>
                         </subviews>