问题
I have a textfield in a UIAlertController and I am trying to implement the delegate method textFieldShouldReturn: which doesn't get called. But i tried implementing the method textFieldDidEndEditing: which gets called without any problem. Please help me here. This is how i do it,
__weak typeof(self) weakSelf = self;
[alertController addTextFieldWithConfigurationHandler:^(UITextField
*textField) {
textField.placeholder = @"Product upc";
textField.textAlignment = NSTextAlignmentCenter;
textField.returnKeyType = UIReturnKeyGo;
textField.delegate = weakSelf;
}];
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@"textfield should return");
//do something
[textField resignFirstResponder];
return NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"end editing ");
}
来源:https://stackoverflow.com/questions/40474328/textfieldshouldreturn-is-not-called-but-textfielddidendediting-gets-called