31 [self.textFieldBeingEdited resignFirstResponder]; |
31 [self.textFieldBeingEdited resignFirstResponder]; |
32 } |
32 } |
33 |
33 |
34 // set the new value |
34 // set the new value |
35 -(BOOL) save:(id) sender { |
35 -(BOOL) save:(id) sender { |
|
36 NSInteger index = textFieldBeingEdited.tag; |
36 if (textFieldBeingEdited != nil) { |
37 if (textFieldBeingEdited != nil) { |
37 if (TEAMNAME_TAG == selectedHog) { |
38 if (TEAMNAME_TAG == index) { |
38 NSLog(@"%@", textFieldBeingEdited.text); |
39 NSLog(@"%@", textFieldBeingEdited.text); |
39 [self.teamDictionary setObject:textFieldBeingEdited.text forKey:@"teamname"]; |
40 [self.teamDictionary setObject:textFieldBeingEdited.text forKey:@"teamname"]; |
40 } else { |
41 } else { |
41 //replace the old value with the new one |
42 //replace the old value with the new one |
42 NSDictionary *oldHog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
43 NSDictionary *oldHog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:index]; |
43 NSMutableDictionary *newHog = [[NSMutableDictionary alloc] initWithDictionary: oldHog]; |
44 NSMutableDictionary *newHog = [[NSMutableDictionary alloc] initWithDictionary: oldHog]; |
44 [newHog setObject:textFieldBeingEdited.text forKey:@"hogname"]; |
45 [newHog setObject:textFieldBeingEdited.text forKey:@"hogname"]; |
45 [[teamDictionary objectForKey:@"hedgehogs"] replaceObjectAtIndex:selectedHog withObject:newHog]; |
46 [[teamDictionary objectForKey:@"hedgehogs"] replaceObjectAtIndex:index withObject:newHog]; |
46 [newHog release]; |
47 [newHog release]; |
47 } |
48 } |
48 |
49 |
49 isWriteNeeded = YES; |
50 isWriteNeeded = YES; |
50 [self.textFieldBeingEdited resignFirstResponder]; |
51 [self.textFieldBeingEdited resignFirstResponder]; |
54 } |
55 } |
55 |
56 |
56 // the textfield is being modified, update the navigation controller |
57 // the textfield is being modified, update the navigation controller |
57 -(void) textFieldDidBeginEditing:(UITextField *)aTextField{ |
58 -(void) textFieldDidBeginEditing:(UITextField *)aTextField{ |
58 self.textFieldBeingEdited = aTextField; |
59 self.textFieldBeingEdited = aTextField; |
59 selectedHog = aTextField.tag; |
60 |
60 UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from the hog name table") |
61 UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from the hog name table") |
61 style:UIBarButtonItemStylePlain |
62 style:UIBarButtonItemStylePlain |
62 target:self |
63 target:self |
63 action:@selector(cancel:)]; |
64 action:@selector(cancel:)]; |
64 self.navigationItem.leftBarButtonItem = cancelButton; |
65 self.navigationItem.leftBarButtonItem = cancelButton; |
80 // the textfield has been modified, check for empty strings and restore original navigation bar |
81 // the textfield has been modified, check for empty strings and restore original navigation bar |
81 -(void) textFieldDidEndEditing:(UITextField *)aTextField{ |
82 -(void) textFieldDidEndEditing:(UITextField *)aTextField{ |
82 if ([textFieldBeingEdited.text length] == 0) |
83 if ([textFieldBeingEdited.text length] == 0) |
83 textFieldBeingEdited.text = [NSString stringWithFormat:@"hedgehog %d",textFieldBeingEdited.tag]; |
84 textFieldBeingEdited.text = [NSString stringWithFormat:@"hedgehog %d",textFieldBeingEdited.tag]; |
84 |
85 |
85 //self.textFieldBeingEdited = nil; |
86 self.textFieldBeingEdited = nil; |
86 self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem; |
87 self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem; |
87 self.navigationItem.leftBarButtonItem = nil; |
88 self.navigationItem.leftBarButtonItem = nil; |
88 } |
89 } |
89 |
90 |
90 // limit the size of the field to 64 characters like in original frontend |
91 // limit the size of the field to 64 characters like in original frontend |
252 |
253 |
253 aTextField.clearsOnBeginEditing = NO; |
254 aTextField.clearsOnBeginEditing = NO; |
254 aTextField.returnKeyType = UIReturnKeyDone; |
255 aTextField.returnKeyType = UIReturnKeyDone; |
255 aTextField.adjustsFontSizeToFitWidth = YES; |
256 aTextField.adjustsFontSizeToFitWidth = YES; |
256 aTextField.delegate = self; |
257 aTextField.delegate = self; |
|
258 aTextField.tag = [indexPath row]; |
257 aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
259 aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
258 aTextField.clearButtonMode = UITextFieldViewModeWhileEditing; |
260 aTextField.clearButtonMode = UITextFieldViewModeWhileEditing; |
259 [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit]; |
261 [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit]; |
260 [cell.contentView addSubview:aTextField]; |
262 [cell.contentView addSubview:aTextField]; |
261 [aTextField release]; |
263 [aTextField release]; |
285 for (UIView *oneView in cell.contentView.subviews) { |
287 for (UIView *oneView in cell.contentView.subviews) { |
286 if ([oneView isMemberOfClass:[UITextField class]]) { |
288 if ([oneView isMemberOfClass:[UITextField class]]) { |
287 // we find the uitextfied and we'll use its tag to understand which one is being edited |
289 // we find the uitextfied and we'll use its tag to understand which one is being edited |
288 UITextField *textFieldFound = (UITextField *)oneView; |
290 UITextField *textFieldFound = (UITextField *)oneView; |
289 textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"]; |
291 textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"]; |
290 textFieldFound.tag = row; |
|
291 } |
292 } |
292 } |
293 } |
293 |
294 |
294 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; |
295 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; |
295 break; |
296 break; |
331 default: |
332 default: |
332 cell = [aTableView cellForRowAtIndexPath:indexPath]; |
333 cell = [aTableView cellForRowAtIndexPath:indexPath]; |
333 for (UIView *oneView in cell.contentView.subviews) { |
334 for (UIView *oneView in cell.contentView.subviews) { |
334 if ([oneView isMemberOfClass:[UITextField class]]) { |
335 if ([oneView isMemberOfClass:[UITextField class]]) { |
335 textFieldBeingEdited = (UITextField *)oneView; |
336 textFieldBeingEdited = (UITextField *)oneView; |
336 textFieldBeingEdited.tag = row; |
|
337 [textFieldBeingEdited becomeFirstResponder]; |
337 [textFieldBeingEdited becomeFirstResponder]; |
338 } |
338 } |
339 } |
339 } |
340 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
340 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
341 break; |
341 break; |