Home:ALL Converter>Setting the delegate of a UITextField programatically from a UIView

Setting the delegate of a UITextField programatically from a UIView

Ask Time:2014-09-12T13:34:19         Author:Aaron Deutsch

Json Formatter

I have a custom UIView which creates a UITextField as a subview while the application is running. I have been stuck on this for hours now, but cannot figure out how to create delegates to hide the keyboard and determine when the "done" button is pressed. I'm still pretty new to iOS development, so any help here would be greatly appreciated.

Thanks.

Author:Aaron Deutsch,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25801416/setting-the-delegate-of-a-uitextfield-programatically-from-a-uiview
Sumit Sharma :

u can do this set \n\nyourtextfieldname.delegate=self;\n\n\nwhen u hide your keyboard.. then u can call that textfield and do this code... \n\n [txtfieldname resignFirstResponder];\n\n\nor u can try this.. also \n\n- (void)textFieldDidEndEditing:(UITextField *)textField\n{\n [yourtextfieldname resignFirstResponder];\n}\n\n\nor best method\n\n-(BOOL)textfieldshouldreturn:(UITextField *)textField\n{\n [textField resignFirstResponder];\n }\n",
2014-09-12T05:39:33
Ramya Yenduri :

If you are using keyboard done button, set the delegate to the textfield\n\ntexfield.delegate = self;\n\n\nthen the below method will be called when done button is clicked \n\n-(BOOL)textFieldShouldReturn:(UITextField *)textField\n\n{\n\n [textField resignFirstResponder];\n return YES;\n\n}\n\n\nIf you are using done button on a toolbar created by you then add a target to the doneButton then call below method in the selector\n\n[textField resignFirstResponder];\n",
2014-09-12T05:57:41
yy