模糊搜索

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    [self.filteredData removeAllObjects]; // First clear the filtered array.
    for (Product *product in tableData)
    {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:
           @"(SELF contains[cd] %@)", searchText];
       [product.productID compare:searchText options:NSCaseInsensitiveSearch];
        BOOL resultID = [predicate evaluateWithObject:product.productID];
        BOOL resultName = [predicate evaluateWithObject:product.productName];
       if([scope isEqualToString:@"Product ID"] && resultID)
        {
            [self.filteredData addObject:product];
        }
        if([scope isEqualToString:@"Product Name"] && resultName)
        {
            [self.filteredData addObject:product];
        }
        if([scope isEqualToString:@"Any"] && (resultID || resultName))
        {
            [self.filteredData addObject:product];
        }
    }
}

你可能感兴趣的:(scope)