0

在自动完成搜索中,我想从 tableview 中获取数据。我使用下面的代码进行自动搜索,但不是自动搜索。如果有人知道,请帮助我

- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
    // Put anything that starts with this substring into the autocompleteUrls array
    // The items in this array is what will show up in the table view
    [autoCompleteData removeAllObjects];
    for(NSString *curString in pastData) {
        NSRange substringRange = [curString rangeOfString:substring];
        if (substringRange.length!= 0) {
            [autoCompleteData addObject:curString];  
        }
    }
    [routeName reloadData];
}
4

1 回答 1

0

您需要在每次击键时过滤数据。您可以在textField:shouldChangeCharactersInRange:replacementString:.

我建议您只过滤表格视图的数据数组和reloadData. 使用谓词,您可以以闪电般的速度和很少的代码进行过滤:

autoCompleteData = [currentDataArray filteredArrayUsingPredicate:
  [NSPredicate predicateWithFormat:@"self CONTAINS[cd] %@", search text]]; 
于 2013-03-29T13:51:35.493 回答