I currently have a UITextField with default text and set to clear when editing begins. I’m trying to make it so that if the field is empty or nil when editing is done the text value will be the default text again. I’m having trouble detecting when either editing is done or the keyboard is dismissed. Could anyone tell me which detection method I would want to use and how to implement it? Thanks so much!
Edit
A placeholder can’t be used in my case
I think you don’t need to handle “default text” yourself. Check
placeholderproperty ofUITextFieldclass.Update
So
placeholderis not good for your case. Did you try to implementUITextFieldDelegatemethods for yourUITextFieldand change the text intextViewDidEndEditing:?To do so, implement
UITextFieldDelegatemethods those look useful for your scenario in your view controller, and setdelegateof yourUITextFieldto the view controller (either by Interface Builder or programmatically). Set the default text intextViewDidEndEditing:method.You can refer to the “Getting the Entered Text and Setting Text” section of Text, Web, and Editing Programming Guide for iOS.