-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringController.m
More file actions
112 lines (86 loc) · 3.14 KB
/
StringController.m
File metadata and controls
112 lines (86 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// StringController.m
// OWForms
//
// Created by Madson on 25/09/10.
// Copyright 2009 Owera. All rights reserved.
//
#import "StringController.h"
#import "OWFieldTextDedicated.h"
@implementation StringController
@synthesize field;
@synthesize textField;
@synthesize tableViewCell;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = field.label;
self.tableView.allowsSelection = NO;
if (field.keyboardType == UIKeyboardTypeDefault)
textField.keyboardType = UIKeyboardTypeDefault;
else
textField.keyboardType = field.keyboardType;
if (field.capitalizationType == UITextAutocapitalizationTypeWords)
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
else
textField.autocapitalizationType = field.capitalizationType;
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Cancelar" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelar)] autorelease];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"OK", @"") style:UIBarButtonItemStyleDone target:self action:@selector(doneAction:)];
self.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
self.navigationItem.hidesBackButton = YES;
}
- (void)cancelar {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)doneAction:(id)sender {
NSString *texto = textField.text;
[texto stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (texto == nil || [texto isEqualToString:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Campos nulos", nil)
message:NSLocalizedString(@"Você precisa preencher os campos para continuar.", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
[alert show];
[alert release];
}else{
field.value = textField.text;
[textField resignFirstResponder];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellId = @"celulaPersonalizada";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:cellId];
if (nil == cell)
cell = tableViewCell;
return cell;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
field.value = textField.text;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[textField setText:(NSString *)field.value];
textField.placeholder = NSLocalizedString(@"Digite aqui", nil);
if (field.isPassword) textField.secureTextEntry = YES;
[self.tableView reloadData];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[textField becomeFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
@end