这是我的问题。我创建了一个UITextField。为什么我的UITextField委托方法不被调用?
.h文件中:
@property (strong, nonatomic) UITextField *emailTextField;
.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];
}
目的是保存用户放在文本字段中的文本。我尝试使用委托方法
-(void)textFieldDidEndEditing:(UITextField *)textField
但该方法没有被调用(我把一个NSLog检查)。有人可以帮忙吗?
我有其他的textField(self.passwordTextField和self.nameTextField)。这就是我使用函数的原因。所以我不能把你的代码放到我的代码中。 – Zoomzoom
检查编辑的代码 – santhu
它的工作!非常感谢!! – Zoomzoom