Blame client/iOS/Views/EditSecretTextTableViewCell.m

Packit 1fb8d4
/*
Packit 1fb8d4
 Custom table cell with secret edit text field
Packit 1fb8d4
 
Packit 1fb8d4
 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
Packit 1fb8d4
 
Packit 1fb8d4
 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 
Packit 1fb8d4
 If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#import "EditSecretTextTableViewCell.h"
Packit 1fb8d4
Packit 1fb8d4
@implementation EditSecretTextTableViewCell
Packit 1fb8d4
Packit 1fb8d4
@synthesize label = _label, textfield = _textfield;
Packit 1fb8d4
Packit 1fb8d4
- (void)awakeFromNib
Packit 1fb8d4
{
Packit 1fb8d4
    [super awakeFromNib];
Packit 1fb8d4
    [_unhide_button setTitle:NSLocalizedString(@"Unhide", @"Button title 'Unhide'") forState:UIControlStateNormal];
Packit 1fb8d4
    [_unhide_button addTarget:self action:@selector(togglePasswordMode:) forControlEvents:UIControlEventTouchUpInside];     
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
- (void)setEnabled:(BOOL)enabled
Packit 1fb8d4
{
Packit 1fb8d4
    [_label setEnabled:enabled];
Packit 1fb8d4
    [_textfield setEnabled:enabled];
Packit 1fb8d4
    [_unhide_button setEnabled:enabled];
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
#pragma mark - action handlers
Packit 1fb8d4
- (void)togglePasswordMode:(id)sender
Packit 1fb8d4
{
Packit 1fb8d4
    BOOL isSecure = [_textfield isSecureTextEntry];
Packit 1fb8d4
Packit 1fb8d4
    if (isSecure)
Packit 1fb8d4
    {
Packit 1fb8d4
        [_unhide_button setTitle:NSLocalizedString(@"Hide", @"Button title 'Hide'") forState:UIControlStateNormal];
Packit 1fb8d4
        [_textfield setSecureTextEntry:NO];        
Packit 1fb8d4
    }
Packit 1fb8d4
    else
Packit 1fb8d4
    {
Packit 1fb8d4
        BOOL first_responder = [_textfield isFirstResponder];
Packit 1fb8d4
        // little trick to make non-secure to secure transition working - this seems to be an ios bug:
Packit 1fb8d4
        // http://stackoverflow.com/questions/6710019/uitextfield-securetextentry-works-going-from-yes-to-no-but-changing-back-to-y
Packit 1fb8d4
        [_textfield setEnabled:NO];   
Packit 1fb8d4
        [_unhide_button setTitle:NSLocalizedString(@"Unhide", @"Button title 'Unhide'") forState:UIControlStateNormal];        
Packit 1fb8d4
        [_textfield setSecureTextEntry:YES];        
Packit 1fb8d4
        [_textfield setEnabled:YES];
Packit 1fb8d4
        if (first_responder)
Packit 1fb8d4
            [_textfield becomeFirstResponder];
Packit 1fb8d4
    }
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
@end