I have the following UISearchbar code:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSTimer *myTimer;
NSLog(@"Timer=%@",myTimer);
if (myTimer)
{
if ([myTimer isValid])
{
[myTimer invalidate];
}
myTimer=nil;
}
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(OnTextChange) userInfo:nil repeats:NO];
}
after writing above code my log shows Timer=null,
OnTextChange is method which fetches data from Url.
Thanks in advance !!
Please write this line in .h file
NSTimer *myTimer;
and then do it in .m file
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(@"Timer=%@",myTimer);
if (myTimer)
{
if ([myTimer isValid])
{
[myTimer invalidate];
}
myTimer=nil;
}
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(OnTextChange) userInfo:nil repeats:NO];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With