project_files/HedgewarsMobile/Classes/EditableCellView.m
branchios-revival
changeset 11256 3dc674af7662
parent 11220 76fd61a88c1e
child 11554 893722a2a1f9
equal deleted inserted replaced
11254:7f3f96e9fdf1 11256:3dc674af7662
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
    17  */
    17  */
    18 
    18 
    19 
    19 
    20 #import "EditableCellView.h"
    20 #import "EditableCellView.h"
    21 
    21 #import "UITableViewCell+FindTable.h"
    22 
    22 
    23 @implementation EditableCellView
    23 @implementation EditableCellView
    24 @synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, respectEditing, oldValue;
    24 @synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, respectEditing, oldValue;
    25 
    25 
    26 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    26 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   101 
   101 
   102 // allow editing only if delegate is set and conformant to protocol, and if editableOnlyWhileEditing
   102 // allow editing only if delegate is set and conformant to protocol, and if editableOnlyWhileEditing
   103 -(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField {
   103 -(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField {
   104     return (delegate != nil) &&
   104     return (delegate != nil) &&
   105            [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)] &&
   105            [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)] &&
   106            (respectEditing) ? ((UITableView*)[self superview]).editing : YES;
   106            (respectEditing) ? [self findTable].editing : YES;
   107 }
   107 }
   108 
   108 
   109 // the textfield is being modified, update the navigation controller
   109 // the textfield is being modified, update the navigation controller
   110 -(void) textFieldDidBeginEditing:(UITextField *)aTextField{
   110 -(void) textFieldDidBeginEditing:(UITextField *)aTextField{
   111     // don't interact with table below
   111     // don't interact with table below
   112     ((UITableView*)[self superview]).scrollEnabled = NO;
   112     [self findTable].scrollEnabled = NO;
   113 
   113 
   114     self.oldValue = self.textField.text;
   114     self.oldValue = self.textField.text;
   115 
   115 
   116     UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"")
   116     UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"")
   117                                                                      style:UIBarButtonItemStylePlain
   117                                                                      style:UIBarButtonItemStylePlain
   145     // this forces a save when user selects a new field
   145     // this forces a save when user selects a new field
   146     if ([self.textField.text isEqualToString:self.oldValue] == NO)
   146     if ([self.textField.text isEqualToString:self.oldValue] == NO)
   147         [self save:aTextField];
   147         [self save:aTextField];
   148 
   148 
   149     // restores default behaviour on caller
   149     // restores default behaviour on caller
   150     ((UITableView*)[self superview]).scrollEnabled = YES;
   150     [self findTable].scrollEnabled = YES;
   151     [(UITableViewController *)delegate navigationItem].leftBarButtonItem = [(UITableViewController *)delegate navigationItem].backBarButtonItem;
   151     [(UITableViewController *)delegate navigationItem].leftBarButtonItem = [(UITableViewController *)delegate navigationItem].backBarButtonItem;
   152     [(UITableViewController *)delegate navigationItem].rightBarButtonItem = nil;
   152     [(UITableViewController *)delegate navigationItem].rightBarButtonItem = nil;
   153 }
   153 }
   154 
   154 
   155 #pragma mark -
   155 #pragma mark -