我的很多代码都基于Apple的TableSearch示例,但是我的应用程序包含需要搜索的35,000个单元,而不是示例中的少数几个。由于UISearchDisplayController相对较新,因此没有太多有关UISearchDisplayController的文档。我使用的代码如下:调整iPhone TableSearch算法以防止UI延迟
- (void)filterContentForSearchText:(NSString*)searchText {
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
for (Entry *entry in appDelegate.entries)
{
if (appDelegate.searchEnglish == NO) {
NSComparisonResult result = [entry.gurmukhiEntry compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:entry];
}
}
else {
NSRange range = [entry.englishEntry rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(range.location != NSNotFound)
{
[self.filteredListContent addObject:entry];
}
}
}}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterContentForSearchText:searchString];
[self.view bringSubviewToFront:keyboardView];
// Return YES to cause the search result table view to be reloaded.
return YES;}
我的问题是有一点的延迟按下键盘上的每个按钮后。这成为一个可用性问题,因为用户在输入每个字符后必须等待App搜索数组以匹配结果。如何调整此代码,以便用户可以连续输入而不会有任何延迟。在这种情况下,延迟数据重新加载所需的时间是可以的,但在键入时不应阻塞键盘。
不正是我期待的...我已经看到它在用户键入之前完成,有延迟加载表格,但它与可以自由输入大型数据库的键盘分开。 – Kulpreet 2009-07-29 07:41:00