26
26
27
27
#import " HKFormTableViewCell.h"
28
28
29
- @interface HKFormController (Private)
29
+ @interface HKFormController ()
30
+
31
+ @property (assign ) UIEdgeInsets originalInset;
30
32
31
33
- (HKFormTableViewCell *)cellWithTextField : (UITextField *)textField ;
32
34
@@ -90,14 +92,16 @@ - (void)didReceiveMemoryWarning
90
92
- (void )viewDidLoad
91
93
{
92
94
[super viewDidLoad ];
93
-
95
+
94
96
[self setupEnclosingNavigationController ];
95
97
96
98
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (keyboardDidShowNotification: ) name: UIKeyboardDidShowNotification object: nil ];
99
+
100
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (keyboardDidHideNotification: ) name: UIKeyboardDidHideNotification object: nil ];
97
101
}
98
102
99
103
- (void )setupEnclosingNavigationController
100
- {
104
+ {
101
105
self.title = [self .definition objectForKey: @" title" ];
102
106
self.navigationItem .rightBarButtonItem = [[[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemDone
103
107
target: self
@@ -185,11 +189,12 @@ - (void)ensureTableViewVisible
185
189
CGRect tframe = self.tableView .frame ;
186
190
CGRect kframe = [self .view convertRect: self .currentKeyboardFrame fromView: nil ];
187
191
CGRect intersect = CGRectIntersection ( tframe, kframe );
188
-
192
+
189
193
if ( CGRectIsNull ( intersect ) )
190
194
return ;
191
195
192
- self.tableView .contentInset = UIEdgeInsetsMake ( 0.0 , 0.0 , intersect.size .height , 0.0 );
196
+ self.originalInset = self.tableView .contentInset ;
197
+ self.tableView .contentInset = UIEdgeInsetsMake ( self.tableView .contentInset .top , 0.0 , intersect.size .height , 0.0 );
193
198
}
194
199
195
200
- (void )ensureTableViewCellVisible : (UITableViewCell *)tableViewCell
@@ -248,15 +253,15 @@ - (BOOL)ensureRequiredFieldsFilled
248
253
cancelButtonTitle: [self localize: @" OK" ]
249
254
otherButtonTitles: nil ];
250
255
NSInteger tag = ( HK_FORM_TAG_OFFSET + section * 1000 + row );
251
-
256
+
252
257
[alertView show ];
253
258
254
259
while ( alertView.visible && [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.1 ]] )
255
260
{
256
261
}
257
262
258
263
[alertView release ];
259
-
264
+
260
265
field = (UITextField *) [self .view viewWithTag: tag];
261
266
262
267
if ( field )
@@ -280,7 +285,7 @@ - (IBAction)handleDone:(id)sender
280
285
if ( [self ensureRequiredFieldsFilled ] )
281
286
{
282
287
[self .parentViewController dismissViewControllerAnimated: YES completion: nil ];
283
-
288
+
284
289
[[NSNotificationCenter defaultCenter ] postNotificationName: HK_FORM_NOTIFICATION_DONE_EDITING object: self ];
285
290
}
286
291
}
@@ -312,10 +317,17 @@ - (void)keyboardDidShowNotification:(NSNotification *)notification
312
317
[self ensureTableViewCellVisible: [self cellWithTextField: self .currentTextField]];
313
318
}
314
319
320
+
321
+ - (void )keyboardDidHideNotification : (NSNotification *)notification
322
+ {
323
+ self.tableView .contentInset = self.originalInset ;
324
+ }
325
+
326
+
315
327
#pragma mark UITextFieldDelegate Methods
316
328
317
329
- (void )textFieldDidBeginEditing : (UITextField *)textField
318
- {
330
+ {
319
331
_editing = YES ; self.currentTextField = textField;
320
332
321
333
[self ensureTableViewCellVisible: [self cellWithTextField: self .currentTextField]];
@@ -338,7 +350,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
338
350
}
339
351
340
352
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section
341
- {
353
+ {
342
354
return [[[[self .definition objectForKey: @" sections" ] objectAtIndex: section] objectForKey: @" children" ] count ];
343
355
}
344
356
@@ -366,7 +378,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
366
378
367
379
cell.selectionStyle = UITableViewCellSelectionStyleNone;
368
380
369
- cell.formLabel .text = [[ self localize: [child objectForKey: @" title" ]] lowercaseString ];
381
+ cell.formLabel .text = [self localize: [child objectForKey: @" title" ]];
370
382
371
383
cell.formField .placeholder = [NSString stringWithFormat: @" %@%@%@ " , [self localize: [child objectForKey: @" placeholder" ]], ( required ? @" " : @" " ), ( required ? @" " : [self localize: @" (optional)" ] )];
372
384
0 commit comments