1
Hy all,我开发了一个应用程序,用于搜索连接到sqlite数据库的表视图。 搜索栏被添加到应用程序和搜索工作正常,但是当我输入时,我只需要按字母键入的项目出现。 这是我的代码,直到现在:Xcode:搜索栏筛选
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
if(text.length == 0)
{
isFiltered = FALSE;
}
else
{
isFiltered = true;
filteredTableData = [[NSMutableArray alloc] init];
for (Author* author in theauthors)
{ //[NSPredicate predicateWithFormat:@"SELECT * from books where title LIKE %@", searchBar.text];
NSRange nameRange = [author.name rangeOfString:text options:NSCaseInsensitiveSearch];
NSRange descriptionRange = [author.genre rangeOfString:text options:NSCaseInsensitiveSearch];
if(nameRange.location != NSNotFound || descriptionRange.location != NSNotFound)
{
[filteredTableData addObject:author];
}
}
}
[self.tableView reloadData];
}