-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditNotesField.m
executable file
·189 lines (143 loc) · 5.88 KB
/
EditNotesField.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// EditNotesField.m
// TradeShowInfo
//
// Created by Bright Creek on 4/28/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "EditNotesField.h"
#import "Constants.h"
@implementation EditNotesField
@synthesize noteCell;
@synthesize keyboardToolbar;
@synthesize editNote;
-(void)viewDidLoad{
[super viewDidLoad];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonClicked:)];
self.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
self.view.backgroundColor = [Constants backgroundColor];
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (IBAction)dismissKeyboard:(id)sender
{
[self dispearAllTextfield];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
noteCell.notesCell.textView.text = editNote;
noteCell.notesCell.textView.editable = NO;
}
-(IBAction)doneButtonClicked:(id)sender{
//UIBarButtonItem *temp = (UIBarButtonItem)sender;
if (noteCell.notesCell.textView.editable == FALSE) {
self.navigationItem.rightBarButtonItem.title = @"Done";
noteCell.notesCell.textView.editable = YES;
[noteCell.notesCell.textView becomeFirstResponder];
}else {
self.navigationItem.rightBarButtonItem.title = @"Edit";
noteCell.notesCell.textView.editable = NO;
editNote = noteCell.notesCell.textView.text;
[editNote retain];
[noteCell.notesCell.textView resignFirstResponder];
}
}
-(IBAction)backButtonClicked:(id)sender{
//[self.];
}
- (void)dispearAllTextfield{
[noteCell.notesCell.textView resignFirstResponder];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
UIViewAnimationCurve animationCurve = [[[notification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
NSTimeInterval animationDuration = [[[notification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
if(nil == keyboardToolbar) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,44)];
keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
keyboardToolbar.tintColor = [UIColor darkGrayColor];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissKeyboard:)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *items = [[NSArray alloc] initWithObjects:flex, barButtonItem, nil];
[keyboardToolbar setItems:items];
[barButtonItem release];
[flex release];
[items release];
}
CGFloat x=0.0;
CGFloat y=self.view.frame.size.height - 196.0;
keyboardToolbar.frame = CGRectMake(x,
y,
keyboardToolbar.frame.size.width,
keyboardToolbar.frame.size.height);
NSLog(@"%f,%f,%f,%f",x,y,keyboardToolbar.frame.size.width,keyboardToolbar.frame.size.height);
[self.view.window addSubview:keyboardToolbar];
[UIView beginAnimations:@"RS_showKeyboardAnimation" context:nil];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
keyboardToolbar.alpha = 1.0;
[UIView commitAnimations];
keyboardToolbarShouldHide = YES;
}
- (void)keyboardWillHide:(NSNotification *)notification
{
if (nil == keyboardToolbar || !keyboardToolbarShouldHide) {
return;
}
CGPoint endCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterEndUserInfoKey] CGPointValue];
CGRect keyboardBounds = [[[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [[[notification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
NSTimeInterval animationDuration = [[[notification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:@"RS_hideKeyboardAnimation" context:nil];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
keyboardToolbar.alpha = 0.0;
keyboardToolbar.frame = CGRectMake(endCentre.x - (keyboardBounds.size.width/2),
endCentre.y - (keyboardBounds.size.height/2) - keyboardToolbar.frame.size.height,
keyboardToolbar.frame.size.width,
keyboardToolbar.frame.size.height);
[UIView commitAnimations];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"EditNotesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(indexPath.section == 0){
if (noteCell == nil) {
NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"NoteCell"
owner:self
options:nil];
cell=[array objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
noteCell = (NoteCell *)cell;
[noteCell retain];
}else {
cell = noteCell;
}
return cell;
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 400.0;
}
- (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;
}
- (void)dealloc {
[super dealloc];
}
@end