Zoomzoom Zoomzoom - 1 month ago 15
iOS Question

UITextField delegate not called

Here's my problem. I created an UITextField (here's the .h file)

@property (strong, nonatomic) UITextField *emailTextField;


The .m file:

- (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];
}


The aim is to save the text that the user put in the TextField. I tried with the delegate methode -(void)textFieldDidEndEditing:(UITextField *)textField but this function is not called (I put a NSLog to check). I don't know how to do. Could someone help me please?

Answer
- (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;
  }