-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivisionRemainderMainViewController.m
More file actions
119 lines (101 loc) · 4.01 KB
/
DivisionRemainderMainViewController.m
File metadata and controls
119 lines (101 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// DivisionRemainderMainViewController.m
// MathHelp
//
// Created by Dominic Surrao on 11/30/11.
// Copyright 2011 MathHelp. All rights reserved.
//
#import "DivisionRemainderMainViewController.h"
#import "DivisionRemainderViewController.h"
@implementation DivisionRemainderMainViewController
@synthesize dividendWhole;
@synthesize dividendFraction;
@synthesize divisor;
@synthesize continueButton;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(loadDivisionRemainderView:)];
self.navigationItem.rightBarButtonItem = doneButtonItem;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (bool)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (IBAction) loadDivisionRemainderView:(id)sender {
NSString *divisorStr = [divisor text];
NSString *dividendStr = [dividendWhole text];
dividendStr = [dividendStr stringByAppendingString:@"."];
dividendStr = [dividendStr stringByAppendingString:[dividendFraction text]];
if (![dividendStr isEqualToString:@"."] && ![divisorStr isEqualToString:@""]) {
DivisionRemainderViewController *divisionRemainderViewController
= [[DivisionRemainderViewController alloc]
initWithNibName:@"DivisionRemainderViewController" bundle:[NSBundle mainBundle]];
divisionRemainderViewController.divisor = [divisorStr intValue];
divisionRemainderViewController.dividend = [NSDecimalNumber decimalNumberWithString:dividendStr];
[[self navigationController] pushViewController:divisionRemainderViewController animated:YES];
}
else {
UIAlertController* alert =
[UIAlertController alertControllerWithTitle:@"Incomplete entry"
message:@"Please enter a complete problem"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction =
[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
}
/* Ensures that a maximum of 1 digit for divisor and 2 digits for each dividend text box is entered */
- (bool)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
int maxLength;
if ([textField isEqual:divisor]) {
maxLength = 1;
}
else {
maxLength = 2;
}
if ([string length] == maxLength) {
textField.text = string;
[textField resignFirstResponder];
}
return !([newString length] > maxLength);
}
/*
When the user hits return, check if the correct entry has been made in the text field.
*/
- (bool)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
@end