【问题标题】:Xcode : Search Bar FilteringXcode:搜索栏过滤
【发布时间】: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


    【解决方案1】:

    其实很简单。我只需要将选项文件从 options:NSCaseInsensitiveSearch 更改为 option:NSAnchoredSearch 它就像一个魅力

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      相关资源
      最近更新 更多