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