Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds a button to toggle positive/negative.

  • Loading branch information...
commit 7bb801a05cec2794571165e48a96f6711e220cbd 1 parent 6170940
@zonble authored
View
1  SillyCal/SCViewController.h
@@ -13,6 +13,7 @@
- (IBAction)appendText:(id)sender;
- (IBAction)setOperator:(id)sender;
- (IBAction)doCalculation:(id)sender;
+- (IBAction)togglePositiveNegative:(id)sender;
@property (retain, nonatomic) NSDecimalNumber *leftOprand;
@property (retain, nonatomic) NSDecimalNumber *rightOprand;
View
41 SillyCal/SCViewController.m
@@ -6,33 +6,21 @@ @implementation SCViewController
- (void)dealloc
{
- [leftOprand release];
- [rightOprand release];
- [textLabel release];
- [operatorLabel release];
- [super dealloc];
-}
-
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
-{
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- leftOprand = nil;
- rightOprand = nil;
- }
- return self;
+ [leftOprand release], [rightOprand release];
+ [textLabel release], [operatorLabel release];
+ [super dealloc];
}
- (void)viewDidLoad
{
- [super viewDidLoad];
+ [super viewDidLoad];
self.textLabel.text = rightOprand ? [rightOprand stringValue] : @"0";
self.operatorLabel.text = @"";
}
- (void)viewDidUnload
{
- [super viewDidUnload];
+ [super viewDidUnload];
self.textLabel = nil;
self.operatorLabel = nil;
}
@@ -60,13 +48,12 @@ - (IBAction)appendText:(id)sender
NSString *s = [(UIButton *)sender titleLabel].text;
if ([s isEqualToString:@"."]) {
- if ([textLabel.text rangeOfString:@"."].location != NSNotFound) {
- return;
+ if ([textLabel.text rangeOfString:@"."].location == NSNotFound) {
+ textLabel.text = [textLabel.text stringByAppendingString:s];
}
- textLabel.text = [textLabel.text stringByAppendingString:s];
return;
}
- else if ([s isEqualToString:@"0"]) {
+ if ([s isEqualToString:@"0"]) {
if ([textLabel.text isEqualToString:@"0"]) {
return;
}
@@ -86,7 +73,7 @@ - (void)_doCalculation
return;
}
if (operatorSelector == @selector(decimalNumberByDividingBy:) && [rightOprand floatValue] == 0.0) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to devide 0" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to devide 0!" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
return;
@@ -143,6 +130,16 @@ - (IBAction)doCalculation:(id)sender
operatorSelector = NULL;
}
+- (IBAction)togglePositiveNegative:(id)sender
+{
+ if (resetTextLabelOnNextAppending) {
+ self.leftOprand = nil;
+ resetTextLabelOnNextAppending = NO;
+ }
+ NSString *s = self.textLabel.text;
+ self.textLabel.text = [s hasPrefix:@"-"] ? [s substringFromIndex:1] : [@"-" stringByAppendingString:s];
+}
+
#pragma mark Properties
@synthesize leftOprand, rightOprand;
View
48 SillyCal/en.lproj/SCViewController.xib
@@ -2,7 +2,7 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1280</int>
- <string key="IBDocument.SystemVersion">11D50</string>
+ <string key="IBDocument.SystemVersion">11D50b</string>
<string key="IBDocument.InterfaceBuilderVersion">2177</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
@@ -74,6 +74,28 @@
<int key="NSfFlags">16</int>
</object>
</object>
+ <object class="IBUIButton" id="824147081">
+ <reference key="NSNextResponder" ref="774585933"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{95, 207}, {61, 37}}</string>
+ <reference key="NSSuperview" ref="774585933"/>
+ <reference key="NSWindow"/>
+ <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">±</string>
+ <reference key="IBUIHighlightedTitleColor" ref="502110293"/>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <reference key="IBUINormalTitleShadowColor" ref="928471838"/>
+ <reference key="IBUIFontDescription" ref="974072441"/>
+ <reference key="IBUIFont" ref="611341610"/>
+ </object>
<object class="IBUIButton" id="746443476">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">292</int>
@@ -425,7 +447,6 @@
<string key="NSFrame">{{233, 342}, {61, 82}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@@ -708,6 +729,15 @@
</object>
<int key="connectionID">63</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">togglePositiveNegative:</string>
+ <reference key="source" ref="824147081"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">74</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -752,6 +782,7 @@
<reference ref="208894022"/>
<reference ref="517737740"/>
<reference ref="24977012"/>
+ <reference ref="824147081"/>
</array>
<reference key="parent" ref="0"/>
</object>
@@ -863,6 +894,11 @@
<reference key="object" ref="1027447275"/>
<reference key="parent" ref="208894022"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">72</int>
+ <reference key="object" ref="824147081"/>
+ <reference key="parent" ref="774585933"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -892,12 +928,13 @@
<string key="68.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="70.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="71.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="72.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">71</int>
+ <int key="maxID">74</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -909,6 +946,7 @@
<string key="clear:">id</string>
<string key="doCalculation:">id</string>
<string key="setOperator:">id</string>
+ <string key="togglePositiveNegative:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="appendText:">
@@ -927,6 +965,10 @@
<string key="name">setOperator:</string>
<string key="candidateClassName">id</string>
</object>
+ <object class="IBActionInfo" key="togglePositiveNegative:">
+ <string key="name">togglePositiveNegative:</string>
+ <string key="candidateClassName">id</string>
+ </object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="operatorLabel">UILabel</string>
Please sign in to comment.
Something went wrong with that request. Please try again.