-
-
Notifications
You must be signed in to change notification settings - Fork 950
/
Copy pathUITextField+Test.m
58 lines (48 loc) · 1.21 KB
/
UITextField+Test.m
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
//
// UITextField+Test.m
// XLForm Tests
//
// Created by Gaston Borba on 3/25/15.
//
//
#import "UITextField+Test.h"
@implementation UITextField (Test)
- (void)beginEditing
{
[self becomeFirstResponder]; // Returns NO ?
if ([self textFieldShouldBeginEditing]){
if ([self.delegate respondsToSelector:@selector(textFieldDidBeginEditing:)]) {
[self.delegate textFieldDidBeginEditing:self];
}
}
}
- (void)endEditing
{
if ([self textFieldShouldReturn]) {
if ([self.delegate respondsToSelector:@selector(textFieldDidEndEditing:)]) {
[self.delegate textFieldDidEndEditing:self];
}
[self resignFirstResponder];
}
}
-(BOOL)textFieldShouldReturn
{
if ([self.delegate respondsToSelector:@selector(textFieldShouldReturn:)]) {
return [self.delegate textFieldShouldReturn:self];
}
return YES;
}
-(BOOL)textFieldShouldBeginEditing
{
if ([self.delegate respondsToSelector:@selector(textFieldShouldBeginEditing:)]) {
return [self.delegate textFieldShouldBeginEditing:self];
}
return YES;
}
-(void)changeText:(NSString *)string
{
[self beginEditing];
[self setText:string];
[self endEditing];
}
@end