UISearch在输入完整搜索词之前开始

时间:2015-11-07 20:39:22

标签: objective-c uisearchbar uisearchbardelegate ios9.1

这是我的代码:

-(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"];
    }
}

问题是完全搜索在用户输入完整搜索词之前开始(如果选中 exact )。我该如何防止这种情况?

0 个答案:

没有答案