How to detect delete key on an UITextField in iOS 8? -
i have subclassed uitextfield , implemented uikeyinput protocol's deletebackward method detect backspace being pressed. works fine on ios 7 not on ios 8.
deletebackward not called on uitextfield anymore when press backspace key.
i've checked documentation , release notes , nothing points reason why happen. pointers?
you must example mbcontactpicker on github. deletion of contacts @ mbcontactpicker via backspace button on ios8 tested me. , works greatly! can use example.
author of mbcontactpicker use next method: when uitextfield must become empty (or before call becomefirstresponder when empty), save single whitespace symbol there. , when press backspace button (when focus set end of text of uitextfield), method
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)text will work. inside must use check this:
nsstring *resultstring = [textfield.text stringbyreplacingcharactersinrange:range withstring:text]; bool ispressedbackspaceaftersinglespacesymbol = [text isequaltostring:@""] && [resultstring isequaltostring:@""] && range.location == 0 && range.length == 1; if (ispressedbackspaceaftersinglespacesymbol) { // actions deletebackward actions } so, must control uitextfield contains single whitespace.
this not hack. so, user willn't noticed behaviour changed
Comments
Post a Comment