简体   繁体   中英

UISearchBar textDidChange Delays for Remote calls

I am trying to determine how to get UISearchBar to delay calling textDidChange till a few millisecs have passed. My goal is to aggregate multiple keyboard entries into one remote web service call.. As I have it now I call the server every keystroke and this is way too much.

If there is not some way within one of the UISearchBar Delegate methods... is there some other way to accomplish the same goal... namely just do not call the server until the user has paused entering keys?

I have been using this delegate method:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 

Yes, you can use an NSTimer.

Do this:

  1. Create an NSTimer that calls your remote web service call and run it when the user starts typing.
  2. Each time the user enters a key have the timer reset and start again.
  3. If the user stopped typing the NSTimer will fire your web service call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM