Check some edge-cases Division by 0, double decimal points, leading 0s, …
Division by 0 is already handled in the code from the previous task.
For the double decimal points expand the commaPressed: method like in assignment #1:
- (IBAction)commaPressed:(UIButton *)sender { if (textFieldShouldBeCleared) { self.numberTextField.text = @"0."; textFieldShouldBeCleared = NO; } else if ([self.numberTextField.text rangeOfString:@"."].location == NSNotFound) { self.numberTextField.text = [self.numberTextField.text stringByAppendingString:@"."]; } }
And for the leading zeros set textFieldShouldBeCleared like before:
- (void)viewDidLoad { ... textFieldShouldBeCleared = YES; } - (IBAction)resultButtonPressed:(id)sender { ... textFieldShouldBeCleared = YES; } - (IBAction)numberEntered:(UIButton *)sender { if (textFieldShouldBeCleared) { ... if (sender.tag != 0) textFieldShouldBeCleared = NO; } ... } - (IBAction)clearDisplay:(id)sender { ... textFieldShouldBeCleared = YES; }
At this point there is still no MVC but at least the functionality from the previous assignment …
… however as we use floats the results might not what you would expect ;).
![Share on Facebook Facebook](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/facebook.png)
![Share on Twitter twitter](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/twitter.png)
![Share on Reddit reddit](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/reddit.png)
![Pin it with Pinterest pinterest](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/pinterest.png)
![Share on Linkedin linkedin](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/linkedin.png)
![Share on tumblr tumblr](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/tumblr.png)
![Share by email mail](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/16x16/mail.png)
![Share on Facebook Facebook](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/facebook.png)
![Share on Twitter twitter](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/twitter.png)
![Share on Reddit reddit](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/reddit.png)
![Pin it with Pinterest pinterest](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/pinterest.png)
![Share on Linkedin linkedin](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/linkedin.png)
![Share on tumblr tumblr](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/tumblr.png)
![Share by email mail](https://cs193p.m2m.at/wp-content/plugins/social-media-feather/synved-social/image/social/regular/32x32/mail.png)