Yun
Yun

Reputation: 41

Monitor UITextField text changes within specified time

Listen to the text box, enter the contents of the case, there is content input within the 2S does not deal with, after the 2S no content input, exit the edit request interface

Upvotes: 2

Views: 57

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50109

not writing your code here -- but giveng you a detailed instruction of how to use a NSTimer ;) [note that this is just one way but IMHO it is the easiest/most intuitive]

  1. set yourself as delegate of textfield

  2. wait for didBegin notification and set the timer for cancel Editing to 2s there!

  3. if endEditing is called while timer is active, cancel it

  4. if shouldChangeCharacters is called while timer is active, cancel it

  5. if timer wasn't cancelled and fires. tell the textfield to endEditing

Upvotes: 2

Related Questions