gpt4 book ai didi

iphone - 如何检测 UISearchBar/UITextField 的输入暂停?

转载 作者:太空狗 更新时间:2023-10-30 03:16:57 26 4
gpt4 key购买 nike

我有以下 UISearchbar 代码:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString* endpoint =[NSString stringWithFormat:@"http://www.someurl/",
[searchText stringByReplacingOccurrencesOfString:@" " withString:@"+"]];
NSURL* url = [NSURL URLWithString:endpoint];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher beginFetchWithDelegate:self didFinishSelector:@selector(searchResultsFetcher:finishedWithData:error:)];
}

我想在输入暂停后发送此请求,并在每次击中字符时重置计时器。我该怎么做?

最佳答案

它不必使用 NSTimer。

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(request) object:nil];

//.....

[self performSelector:@selector(request) withObject:nil afterDelay:yourpausetime];

}

关于iphone - 如何检测 UISearchBar/UITextField 的输入暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7061377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com