How can I get a textDidChange (like for a UISearchBar) method for a UITextField?

后端 未结 7 808
不知归路
不知归路 2020-12-17 15:23

How can I get a textDidChange method for a UITextField? I need to call a method every time a change is made to a text field. Is this possible? Thanks!

7条回答
  •  轮回少年
    2020-12-17 15:49

    I found some problem when you use replaceCharactersInRange in delegate shouldChangeCharactersInRange.

    Ex: In Vietnamese keyboard string aa -> â, So if you use method replaceCharactersInRange then Incorrect results.

    You can try in this case by event UIControlEventEditingChanged:

    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]
    

提交回复
热议问题