diff options
| author | mo khan <mo@mokhan.ca> | 2013-05-26 20:59:30 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-05-26 20:59:30 -0600 |
| commit | 7d03d266a1394bfc98a34533c49623000cf93fe8 (patch) | |
| tree | a97ece9f4f71e828b8dbcb5aa71737ba1a0ee1e4 | |
| parent | 8f1e8354edc961eefa682871542111bbf4c9569d (diff) | |
add clear button
| -rw-r--r-- | Calculator/Brain.h | 1 | ||||
| -rw-r--r-- | Calculator/Brain.m | 5 | ||||
| -rw-r--r-- | Calculator/ViewController.h | 1 | ||||
| -rw-r--r-- | Calculator/ViewController.m | 8 | ||||
| -rw-r--r-- | Calculator/en.lproj/ViewController.xib | 49 |
5 files changed, 61 insertions, 3 deletions
diff --git a/Calculator/Brain.h b/Calculator/Brain.h index 3babb2f..56f0876 100644 --- a/Calculator/Brain.h +++ b/Calculator/Brain.h @@ -3,4 +3,5 @@ @interface Brain : NSObject -(void) addObject:(double)operand; -(double) performOperation:(NSString *)operation; +-(void) clear; @end diff --git a/Calculator/Brain.m b/Calculator/Brain.m index 836b4cc..f94e095 100644 --- a/Calculator/Brain.m +++ b/Calculator/Brain.m @@ -56,4 +56,9 @@ } return [lastObject doubleValue]; } + +-(void) clear +{ + [self.arrOperands removeAllObjects]; +} @end diff --git a/Calculator/ViewController.h b/Calculator/ViewController.h index 5686cb1..da0264d 100644 --- a/Calculator/ViewController.h +++ b/Calculator/ViewController.h @@ -8,4 +8,5 @@ -(IBAction) numberPressed:(id)sender; -(IBAction) operationPressed:(id)sender; -(IBAction) enterPressed:(id)sender; +-(IBAction) clearPressed:(id)sender; @end diff --git a/Calculator/ViewController.m b/Calculator/ViewController.m index c8fbf4b..23c3a45 100644 --- a/Calculator/ViewController.m +++ b/Calculator/ViewController.m @@ -13,7 +13,6 @@ if (!self.myBrain) { self.myBrain = [[Brain alloc] init]; - self.display.textAlignment = NSTextAlignmentRight; } // Do any additional setup after loading the view, typically from a nib. } @@ -52,4 +51,11 @@ [self.myBrain addObject:[self.display.text doubleValue]]; self.enteringNumber = NO; } + +-(IBAction) clearPressed:(id)sender +{ + self.enteringNumber = NO; + self.display.text = @"0"; + [self.myBrain clear]; +} @end diff --git a/Calculator/en.lproj/ViewController.xib b/Calculator/en.lproj/ViewController.xib index 5035a0f..69cadf9 100644 --- a/Calculator/en.lproj/ViewController.xib +++ b/Calculator/en.lproj/ViewController.xib @@ -57,6 +57,7 @@ </object> <nil key="IBUIHighlightedColor"/> <int key="IBUIBaselineAdjustment">0</int> + <int key="IBUITextAlignment">2</int> <object class="IBUIFontDescription" key="IBUIFontDescription"> <int key="type">1</int> <double key="pointSize">17</double> @@ -340,7 +341,7 @@ <string key="NSFrame">{{236, 185}, {64, 45}}</string> <reference key="NSSuperview" ref="774585933"/> <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="376408545"/> + <reference key="NSNextKeyView" ref="126432707"/> <string key="NSReuseIdentifierKey">_NS:9</string> <bool key="IBUIOpaque">NO</bool> <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string> @@ -425,6 +426,29 @@ <reference key="IBUIFontDescription" ref="394180644"/> <reference key="IBUIFont" ref="350225383"/> </object> + <object class="IBUIButton" id="126432707"> + <reference key="NSNextResponder" ref="774585933"/> + <int key="NSvFlags">292</int> + <string key="NSFrame">{{20, 237}, {64, 45}}</string> + <reference key="NSSuperview" ref="774585933"/> + <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="376408545"/> + <string key="NSReuseIdentifierKey">_NS:9</string> + <bool key="IBUIOpaque">NO</bool> + <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string> + <int key="IBUIContentHorizontalAlignment">0</int> + <int key="IBUIContentVerticalAlignment">0</int> + <int key="IBUIButtonType">1</int> + <string key="IBUINormalTitle">C</string> + <reference key="IBUIHighlightedTitleColor" ref="1071574929"/> + <object class="NSColor" key="IBUINormalTitleColor"> + <int key="NSColorSpace">1</int> + <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes> + </object> + <reference key="IBUINormalTitleShadowColor" ref="103038745"/> + <reference key="IBUIFontDescription" ref="394180644"/> + <reference key="IBUIFont" ref="350225383"/> + </object> </array> <string key="NSFrame">{{0, 20}, {320, 548}}</string> <reference key="NSSuperview"/> @@ -612,6 +636,15 @@ </object> <int key="connectionID">34</int> </object> + <object class="IBConnectionRecord"> + <object class="IBCocoaTouchEventConnection" key="connection"> + <string key="label">clearPressed:</string> + <reference key="source" ref="126432707"/> + <reference key="destination" ref="372490531"/> + <int key="IBEventType">7</int> + </object> + <int key="connectionID">45</int> + </object> </array> <object class="IBMutableOrderedSet" key="objectRecords"> <array key="orderedObjects"> @@ -652,6 +685,7 @@ <reference ref="355688739"/> <reference ref="376408545"/> <reference ref="982545685"/> + <reference ref="126432707"/> </array> <reference key="parent" ref="0"/> </object> @@ -735,6 +769,11 @@ <reference key="object" ref="376408545"/> <reference key="parent" ref="774585933"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">43</int> + <reference key="object" ref="126432707"/> + <reference key="parent" ref="774585933"/> + </object> </array> </object> <dictionary class="NSMutableDictionary" key="flattenedProperties"> @@ -756,6 +795,7 @@ <string key="21.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="23.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> + <string key="43.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> @@ -764,7 +804,7 @@ <nil key="activeLocalization"/> <dictionary class="NSMutableDictionary" key="localizations"/> <nil key="sourceID"/> - <int key="maxID">41</int> + <int key="maxID">45</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <array class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -772,11 +812,16 @@ <string key="className">ViewController</string> <string key="superclassName">UIViewController</string> <dictionary class="NSMutableDictionary" key="actions"> + <string key="clearPressed:">id</string> <string key="enterPressed:">id</string> <string key="numberPressed:">id</string> <string key="operationPressed:">id</string> </dictionary> <dictionary class="NSMutableDictionary" key="actionInfosByName"> + <object class="IBActionInfo" key="clearPressed:"> + <string key="name">clearPressed:</string> + <string key="candidateClassName">id</string> + </object> <object class="IBActionInfo" key="enterPressed:"> <string key="name">enterPressed:</string> <string key="candidateClassName">id</string> |
