0

这是我的代码:

-(void)searchBar:(UISearchBar*)va textDidChange:(NSString*)text  {

NSPredicate *predicate;

//  what are we searching for?
if(doExactSearch == NO) {
    if( [oSearchByISBN isSelected])
        predicate = [NSPredicate predicateWithFormat:@"isbn contains [c] %@", text];
    else if( [oSearchBySKU isSelected])
        predicate = [NSPredicate predicateWithFormat:@"sku contains [c] %@", text];
    else if( [oSearchByTitle isSelected])
        predicate = [NSPredicate predicateWithFormat:@"title contains [c] %@", text];
    else if( [oSearchByAuthor isSelected])
        predicate = [NSPredicate predicateWithFormat:@"author contains [c] %@", text];
    else  {
        CommonMethods *cm  = [[CommonMethods alloc] init];
        [cm showAlertView:@"Error" message:@"You must choose the field to search on"];
    }
}
else if(doExactSearch == YES)  {
    if( [oSearchByISBN isSelected])
        predicate = [NSPredicate predicateWithFormat:@"isbn == %@", text];
    else if( [oSearchBySKU isSelected])
        predicate = [NSPredicate predicateWithFormat:@"sku == %@", text];
    else if( [oSearchByTitle isSelected])
        predicate = [NSPredicate predicateWithFormat:@"title == %@", text];
    else if( [oSearchByAuthor isSelected])
        predicate = [NSPredicate predicateWithFormat:@"author == %@", text];
    else  {
        CommonMethods *cm  = [[CommonMethods alloc] init];
        [cm showAlertView:@"Error" message:@"You must choose the field to search on"];
    }
}

问题是在用户输入完整的搜索词之前,精确的搜索就开始了(如果检查了精确的话)。我该如何防止这种情况?

4

0 回答 0