こんにちは、SQLite データベースに接続されたテーブル ビューを検索するアプリケーションを開発しました。検索バーがアプリケーションに追加され、検索は正常に機能していますが、入力すると、入力した文字で始まる項目のみが表示される必要があります。これは今までの私のコードです:
-(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];
}