Iphone 使用SQLite搜索数据时延迟,并将其放在UITableView上
我有一个带有UITableView的屏幕和一个搜索栏。此搜索是在数据库中进行的,它还必须查看另一个相关表,以及一些内部联接 问题是,在我快速键入单词时会出现延迟,因为当我完成键入单词时,我会看到UITableView会逐字缓慢更新,直到用整个单词完成搜索 下面是一段代码:Iphone 使用SQLite搜索数据时延迟,并将其放在UITableView上,iphone,objective-c,uitableview,sqlite,uisearchbar,Iphone,Objective C,Uitableview,Sqlite,Uisearchbar,我有一个带有UITableView的屏幕和一个搜索栏。此搜索是在数据库中进行的,它还必须查看另一个相关表,以及一些内部联接 问题是,在我快速键入单词时会出现延迟,因为当我完成键入单词时,我会看到UITableView会逐字缓慢更新,直到用整个单词完成搜索 下面是一段代码: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.queue = [[NSOperationQ
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
self.queue = [[NSOperationQueue new] autorelease];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(makeSearch:) object:searchText];
[self.queue addOperation:operation];
[operation release];
}
- (void)makeSearch:(NSString *)_string {
[self.displayItems removeAllObjects];
Users *usr = [[[Users alloc] init] autorelease];
self.displayItems = [[[NSMutableArray alloc] initWithArray:[usr getUsersLike:_string]] autorelease];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
(变量
displayItems
用于填充UITableView)在textDidChange
添加新操作之前,您需要取消队列上的挂起操作,否则您必须等待每个搜索完成,然后才能执行最近的搜索