I want to execute certain code (only once) when user enters three or more character in searchbar. I have used below code :
- (void) searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
if ([searchText length] >= 3) {
[self performSelector:@selector(searchBarSearchButtonClicked:) withObject:theSearchBar afterDelay:3.0];
}
}
The problem in using above code is it executes number of times greater than three. Eg. If five character is entered in searchbar then it executes for three times (desired only once).
How to achieve this? Sure +1 for correct answer.
I found solution by using
NSTimer
. Below is snippet :