【发布时间】:2012-07-20 14:14:55
【问题描述】:
大家好,我开发了一个应用程序来搜索连接到 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];
}
【问题讨论】:
标签: xcode uitableview sqlite uisearchdisplaycontroller