-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddFloViewController.m
88 lines (74 loc) · 2.66 KB
/
AddFloViewController.m
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
//
// AddFloViewController.m
// flojuggler
//
// Created by Selino Valdes on 11/4/13.
// Copyright (c) 2013 Selino Valdes. All rights reserved.
//
#import "AddFloViewController.h"
#import "Flos.h"
@implementation AddFloViewController
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
- (IBAction)KeyboardDoneKeyPressed:(id)sender
{
[sender resignFirstResponder];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if ([_nameField isFirstResponder] && [touch view] != _nameField) {
[_nameField resignFirstResponder];
} else if ([_cycleField isFirstResponder] && [touch view] != _cycleField) {
[_cycleField resignFirstResponder];
} else if ([_lengthField isFirstResponder] && [touch view] != _lengthField) {
[_lengthField resignFirstResponder];
}
[super touchesBegan:touches withEvent:event];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// read newly created object values into fields except for date picker which defaults to today after loading the view.
_nameField.text = [self.currentFlo name];
_cycleField.text = [[self.currentFlo cycle] stringValue];
_lengthField.text = [[self.currentFlo length] stringValue];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)addPhotoBtn {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)cancelFlo:(id)sender {
// dismiss and remove the object
[self.delegate addFloViewControllerDidCancel:[self currentFlo]];
}
- (IBAction)saveFlo:(id)sender {
// dismiss the view and save the context
[self.currentFlo setName:_nameField.text];
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myCycle = [f numberFromString:_cycleField.text];
[self.currentFlo setCycle: myCycle];
NSNumberFormatter * l = [[NSNumberFormatter alloc] init];
[l setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myLength = [l numberFromString:_lengthField.text];
[self.currentFlo setLength: myLength];
[self.currentFlo setStartDate:[_startDatePicker date]];
[self.delegate addFloViewControllerDidSave];
}
@end