project_files/HedgewarsMobile/Classes/EditableCellView.m
author koda
Sun, 07 Nov 2010 23:47:29 +0100
changeset 4208 dd54999c2822
parent 3904 22e4d74240e5
child 4210 caa9b08990eb
permissions -rw-r--r--
revamp gamemodes section in the ifrontend and update ios game modes move minestime and turntime *1000 away from frontend and move it in engine (preserving lua compatibility)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    18
 * File created on 03/07/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3782
diff changeset
    20
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    21
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    22
#import "EditableCellView.h"
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    23
#import "CommodityFunctions.h"
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    24
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    25
@implementation EditableCellView
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
    26
@synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, respectEditing, oldValue;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    27
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    28
-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    29
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    30
        delegate = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    31
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    32
        textField = [[UITextField alloc] initWithFrame:CGRectZero];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    33
        textField.backgroundColor = [UIColor clearColor];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    34
        textField.delegate = self;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    35
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    36
        textField.clearsOnBeginEditing = NO;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    37
        textField.returnKeyType = UIReturnKeyDone;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    38
        textField.adjustsFontSizeToFitWidth = YES;
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
    39
        textField.userInteractionEnabled = YES;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    40
        [textField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    41
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    42
        [self.contentView addSubview:textField];
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    43
        //[textField release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    44
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    45
        titleLabel = [[UILabel alloc] init];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    46
        titleLabel.textAlignment = UITextAlignmentLeft;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    47
        titleLabel.backgroundColor = [UIColor clearColor];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    48
        titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    49
        [self.contentView addSubview:titleLabel];
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    50
        //[titleLabel release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    51
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    52
        minimumCharacters = 1;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    53
        maximumCharacters = 64;
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
    54
        respectEditing = NO;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    55
        oldValue = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    56
    }
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    57
    return self;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    58
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    59
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    60
-(void) layoutSubviews {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    61
    [super layoutSubviews];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    62
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    63
    CGRect contentRect = self.contentView.bounds;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    64
    CGFloat boundsX = contentRect.origin.x;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    65
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    66
    int offset = 0;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    67
    int skew = 0;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    68
    if (self.imageView != nil)
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    69
        offset += self.imageView.frame.size.width;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
    70
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    71
    if ([self.titleLabel.text length] == 0)
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    72
        titleLabel.frame = CGRectZero;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    73
    else {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    74
        titleLabel.frame = CGRectMake(boundsX+offset+10, 10, 100, [UIFont labelFontSize] + 4);
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    75
        offset += 100;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    76
        skew +=2;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    77
    }
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
    78
4208
dd54999c2822 revamp gamemodes section in the ifrontend and update ios game modes
koda
parents: 3904
diff changeset
    79
    // sometimes the bold property gets lost
dd54999c2822 revamp gamemodes section in the ifrontend and update ios game modes
koda
parents: 3904
diff changeset
    80
    textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
3782
dc3531e49e4c add a description field for schemes and weapons
koda
parents: 3697
diff changeset
    81
    textField.frame = CGRectMake(boundsX+offset+10, skew+10, 300, [UIFont labelFontSize] + 4);
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    82
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    83
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    84
-(void) setSelected:(BOOL)selected animated:(BOOL)animated {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    85
    [super setSelected:selected animated:animated];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    86
    // Configure the view for the selected state
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    87
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    88
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    89
-(void) dealloc {
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    90
    self.delegate = nil;
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    91
    releaseAndNil(oldValue);
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    92
    releaseAndNil(titleLabel);
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
    93
    releaseAndNil(textField);
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    94
    [super dealloc];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    95
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    96
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    97
#pragma mark -
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    98
#pragma mark textField delegate
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
    99
// limit the size of the field to 64 characters like in original frontend
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   100
-(BOOL) textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
   101
    return !([aTextField.text length] > self.maximumCharacters && [string length] > range.length);
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   102
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   103
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   104
// allow editing only if delegate is set and conformant to protocol, and if editableOnlyWhileEditing
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   105
-(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField {
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   106
    return (delegate != nil) &&
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   107
           [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)] &&
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   108
           (respectEditing) ? ((UITableView*)[self superview]).editing : YES;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   109
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   110
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   111
// the textfield is being modified, update the navigation controller
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   112
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   113
    // don't interact with table below
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   114
    ((UITableView*)[self superview]).scrollEnabled = NO;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   115
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   116
    self.oldValue = self.textField.text;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   117
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   118
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"")
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   119
                                                                     style:UIBarButtonItemStylePlain
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   120
                                                                    target:self
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   121
                                                                    action:@selector(cancel:)];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   122
    [(UITableViewController *)delegate navigationItem].leftBarButtonItem = cancelButton;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   123
    [cancelButton release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   124
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   125
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"")
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   126
                                                                     style:UIBarButtonItemStyleDone
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   127
                                                                    target:self
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   128
                                                                    action:@selector(save:)];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   129
    [(UITableViewController *)delegate navigationItem].rightBarButtonItem = saveButton;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   130
    [saveButton release];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   131
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   132
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   133
/* with this a field might remain in editing status even if the view moved;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   134
   use method below instead that allows some more interaction
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   135
// don't accept 0-length strings
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   136
-(BOOL) textFieldShouldEndEditing:(UITextField *)aTextField {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   137
    return ([aTextField.text length] > 0);
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   138
}
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   139
*/
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   140
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   141
-(BOOL) textFieldShouldReturn:(UITextField *)aTextField {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   142
    return ([aTextField.text length] >= self.minimumCharacters);
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   143
}
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   144
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   145
// the textfield has been modified, tell the delegate to do something
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   146
-(void) textFieldDidEndEditing:(UITextField *)aTextField {
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   147
    // this forces a save when user selects a new field
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   148
    if ([self.textField.text isEqualToString:self.oldValue] == NO)
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   149
        [self save:aTextField];
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   150
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   151
    // restores default behaviour on caller
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   152
    ((UITableView*)[self superview]).scrollEnabled = YES;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   153
    [(UITableViewController *)delegate navigationItem].rightBarButtonItem = [(UITableViewController *)delegate navigationItem].backBarButtonItem;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   154
    [(UITableViewController *)delegate navigationItem].leftBarButtonItem = nil;
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   155
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   156
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
   157
#pragma mark -
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
   158
#pragma mark instance methods
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3661
diff changeset
   159
// the user wants to show the keyboard
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   160
-(void) replyKeyboard {
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   161
    [self.textField becomeFirstResponder];
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   162
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   163
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   164
// the user pressed cancel so hide keyboard
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   165
-(void) cancel:(id) sender {
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   166
    // reverts any changes and performs a fake save for removing the keyboard
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   167
    self.textField.text = self.oldValue;
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   168
    [self save:sender];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   169
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   170
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   171
// send the value to the delegate (called before textFieldDidEndEditing)
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   172
-(void) save:(id) sender {
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   173
    if (delegate == nil || [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)] == NO)
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   174
        return;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   175
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   176
    // don't save if the textfield is invalid
3878
348f4104461d fix a small glitch in textfield cells and remove cheese from pro
koda
parents: 3829
diff changeset
   177
    if ([self textFieldShouldReturn:textField] == NO)
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   178
        return;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3667
diff changeset
   179
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   180
    [delegate saveTextFieldValue:self.textField.text withTag:self.tag];
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   181
    [self.textField resignFirstResponder];
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   182
    self.oldValue = nil;
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   183
}
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   184
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   185
// when field is editable only when the tableview is editable, resign responder when exiting editing mode
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   186
-(void) willTransitionToState:(UITableViewCellStateMask)state {
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   187
    if (respectEditing && state == UITableViewCellStateDefaultMask)
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   188
        [self save:nil];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   189
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   190
    [super willTransitionToState:state];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   191
}
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3878
diff changeset
   192
3659
f8d5ac50e307 half reworking of the settings page with delegation
koda
parents:
diff changeset
   193
@end