我有一个 uitableview 和 uisearchbar。我正在用大量记录绑定表,并为用户提供可以从中搜索的功能。但是很多时候,当数据量很大时,键盘会卡住直到重新加载表。无论如何,我可以异步搜索。这是 iOS 4 应用程序。
我的 uisearchbar textDidChange 方法如下
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if(searchText.length == 0)
{
isFiltered = FALSE;
}
else
{
@autoreleasepool {
isFiltered = true;
membersMFilterArray = [[NSMutableArray alloc] init];
int lineCount = [[[membersMArray objectAtIndex:0] valueForKey:@"LineCount"] intValue];
NSString *membersMArrayValue;
for (int i=0; i<[membersMArray count]; i++)
{
membersMArrayValue = [membersMArray objectAtIndex:i];
NSString *line;
for (int j=0; j<lineCount; j++)
{
line = [NSString stringWithFormat:@"Line%d",j+1];
NSRange lineRange = [[membersMArrayValue valueForKey:line] rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(lineRange.location != NSNotFound)
{
[membersMFilterArray addObject:[membersMArray objectAtIndex:i]];
break;
}
}
}
}
}
[tblMember reloadData];}
我的数组如下所示,我从中搜索过,实际上这是一个用户数据,它出现在一个表行中,如果有 10000 行,则与此相乘。所以上面的for循环是我认为是因为这种方式。
(
{
Line1 = "Ashish";
Line10 = "Ahmedabad";
Line11 = "Gujarat";
Line12 = "";
Line13 = "India";
Line14 = "";
Line15 = "";
Line16 = "abc@yahoo.com";
Line17 = "";
Line18 = "";
Line19 = "xyz";
Line2 = "Ahmedabad, Gujarat";
Line20 = "Jun 04, 2012";
Line3 = "";
Line4 = "";
Line5 = "";
Line6 = "abc";
Line7 = "xyz";
Line8 = "";
Line9 = "";
LineCount = 20;
"Member_id" = GM00018004;
RowNo = 01;
}
)