我的RootViewController中有一个带有Scopebar的搜索栏。如果我正在搜索项目,它的工作非常好,如果我在范围范围内搜索。 但是,如果用户没有提供Searchtext,怎么可能显示范围结果?
代码示例非常好。
以下是在用户将文本设置为Seachbar之后进行过滤的代码。
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.filteredContent removeAllObjects]; // First clear the filtered array.
for (test *new in tabelle)
{
//cat1
if ([scope isEqualToString:@"cat1"] && [new.Location isEqualToString:@"cat1"])
{
NSComparisonResult result = [new.TText compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredContent addObject:new];
}
}
//cat2
if ([scope isEqualToString:@"cat2"] && [new.Location isEqualToString:@"cat2"])
{
NSComparisonResult result = [new.TText compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredContent addObject:new];
}
}
//all
if ([scope isEqualToString:@"Alle"])
{
NSComparisonResult result = [new.TText compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredContent addObject:new];
}
}
}
}
我想要搜索栏中没有任何类型字母的结果
喜欢这张图片,但没有输入字母:http://edumobile.org/iphone/wp-content/uploads/2010/03/search.jpg