textFieldShouldReturn: is not called but textFieldDidEndEditing: gets called?

[亡魂溺海] 提交于 2019-12-12 03:07:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!