Zoo*_*oom 0 text delegates objective-c uitextfield ios
这是我的问题.我创建了一个UITextField.
.h文件:
@property (strong, nonatomic) UITextField *emailTextField;
Run Code Online (Sandbox Code Playgroud)
.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
self.emailTextField.delegate=self;
[self setTextFields:120 :@" email" :self.emailTextField];
}
-(void)setTextFields:(float)ycoord :(NSString *)text :(UITextField *)textField
{
CGRect frame = CGRectMake(60, ycoord, 180, 30);
textField = [[UITextField alloc]initWithFrame:frame];
textField.backgroundColor = [UIColor whiteColor];
textField.placeholder = text;
textField.font = [UIFont fontWithName:@"Baskerville" size:15];
textField.allowsEditingTextAttributes=YES;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
CALayer *lay = [textField layer];
[lay setCornerRadius:5.0f];
[self.view addSubview:textField];
}
Run Code Online (Sandbox Code Playgroud)
目的是保存用户放在TextField中的文本.我尝试了委托方法
-(void)textFieldDidEndEditing:(UITextField *)textField
Run Code Online (Sandbox Code Playgroud)
但是没有调用该方法(我把一个NSLog检查).有人可以帮忙吗?
- (void)viewDidLoad
{
[super viewDidLoad];
self.emailTextField= [self setTextFields:120 :@" email"];
self.emailTextField.delegate=self;
self.passwordTextField= [self setTextFields:200 :@" password"];
self.passwordTextField.delegate=self;
self.nameTextField= [self setTextFields:250 :@" name"];
self.nameTextField.delegate=self;
}
-(UITextField *)setTextFields:(float)ycoord :(NSString *)text{
CGRect frame = CGRectMake(60, ycoord, 180, 30);
UITextField* textField = [[UITextField alloc]initWithFrame:frame];
textField.backgroundColor = [UIColor whiteColor];
textField.placeholder = text;
textField.font = [UIFont fontWithName:@"Baskerville" size:15];
textField.allowsEditingTextAttributes=YES;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
CALayer *lay = [textField layer];
[lay setCornerRadius:5.0f];
[self.view addSubview:textField];
return textField;
}
Run Code Online (Sandbox Code Playgroud)