FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
EditSecretTextTableViewCell.m
1/*
2 Custom table cell with secret edit text field
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9 */
10
11#import "EditSecretTextTableViewCell.h"
12
13@implementation EditSecretTextTableViewCell
14
15@synthesize label = _label, textfield = _textfield;
16
17- (void)awakeFromNib
18{
19 [super awakeFromNib];
20 [_unhide_button setTitle:NSLocalizedString(@"Unhide", @"Button title 'Unhide'")
21 forState:UIControlStateNormal];
22 [_unhide_button addTarget:self
23 action:@selector(togglePasswordMode:)
24 forControlEvents:UIControlEventTouchUpInside];
25}
26
27- (void)setEnabled:(BOOL)enabled
28{
29 [_label setEnabled:enabled];
30 [_textfield setEnabled:enabled];
31 [_unhide_button setEnabled:enabled];
32}
33
34#pragma mark - action handlers
35- (void)togglePasswordMode:(id)sender
36{
37 BOOL isSecure = [_textfield isSecureTextEntry];
38
39 if (isSecure)
40 {
41 [_unhide_button setTitle:NSLocalizedString(@"Hide", @"Button title 'Hide'")
42 forState:UIControlStateNormal];
43 [_textfield setSecureTextEntry:NO];
44 }
45 else
46 {
47 BOOL first_responder = [_textfield isFirstResponder];
48 // little trick to make non-secure to secure transition working - this seems to be an ios
49 // bug:
50 // http://stackoverflow.com/questions/6710019/uitextfield-securetextentry-works-going-from-yes-to-no-but-changing-back-to-y
51 [_textfield setEnabled:NO];
52 [_unhide_button setTitle:NSLocalizedString(@"Unhide", @"Button title 'Unhide'")
53 forState:UIControlStateNormal];
54 [_textfield setSecureTextEntry:YES];
55 [_textfield setEnabled:YES];
56 if (first_responder)
57 [_textfield becomeFirstResponder];
58 }
59}
60
61@end