ios - Delegate method not working correctly when trying to delete a character from a secured textField text -
i have problem when trying delete character secured textfield text.
i want capture text in textfieldshouldchangecharactersinrange
delegate method, problem secured textfields there problem. when tap on secured textfield , delete on character textfield's text, visually textfield text disappears (this default secured text fields).
the problem text returned in textfiledshouldchangecharactersinrange
not empty text, text without removed character. problem visually there no text left in text field, text returned delegate method mentioned above not nil, or empty.
i want ask if there possibility capture correct text.
if not clear please ask , respond.
thank much!
try
func textfield(textfield: uitextfield, shouldchangecharactersinrange range: nsrange, replacementstring string: string) -> bool { if let swrange = textfield.text!.rangefromnsrange(range) { let newstring = textfield.text!.stringbyreplacingcharactersinrange(swrange,withstring:string) //... print(newstring) } return true }
the method rangefromnsrange(range)
can founded here nsrange range<string.index>
i hope helps you
Comments
Post a Comment