自動(dòng)搜索功能,用戶連續(xù)輸入的時(shí)候不搜索,用戶停止輸入的時(shí)候自動(dòng)搜索
(我這里設(shè)置的是0.5s,可根據(jù)需求更改)
// 輸入框文字改變的時(shí)候調(diào)用
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
// 先取消調(diào)用搜索方法
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(searchNewResult) object:nil];
// 0.5秒后調(diào)用搜索方法
[self performSelector:@selector(searchNewResult) withObject:nil afterDelay:0.5];
}