ko1o / PYSearch

🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .
MIT License
3.83k stars 752 forks source link

搜索建议的问题 #82

Open wudb opened 7 years ago

wudb commented 7 years ago

自定义搜索建议的tableviewcell后,点击cell,会更改searchBar的text 用_swSelf.searchBar.text = didSelectCell.textLabel.text; 既然都自定义cell了,cell的textLabel是不一定有值的,所以searchBar的text变为空了,很奇怪啊! 这时候再拿searchBar的text就不正确了。 建议去掉这句代码

ko1o commented 7 years ago

@wudb 因为这个涉及到搜索缓存!所以如果您有不一样的需求,可以fork,然后根据需求完善代码!

wudb commented 7 years ago

你说的应该是搜索历史的缓存吧,这个其实不冲突的,但是如果不去掉的话,一旦自定义搜索建议之后,搜索历史也没法缓存了

SHRemover commented 7 years ago

本地缓存搜索历史的时候,建议添加一下空字符串的处理、 如果搜索 ” ” 空字符串,前端进行后续的拦截处理,本地的缓存还是存在的、

ko1o commented 7 years ago

@SHRemover 搜索空字符,并没有进行本地缓存!没理解你说的意思,可否再说明一下?

SHRemover commented 7 years ago

我不晓得是否是我这边版本低的问题,我这里搜索空字符串是有做本地缓存的、

#pragma mark - UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    // 回收键盘
    [searchBar resignFirstResponder];
    // 先移除再刷新
// 我在这里进行了空字符串的拦截处理,不然搜索的历史记录,是存在空字符串的、
//    if (![CommonUtils isBlankString:searchBar.text]) {
        [self.searchHistories removeObject:searchBar.text];
        [self.searchHistories insertObject:searchBar.text atIndex:0];
//    }
    // 刷新数据
    if (self.searchHistoryStyle == PYSearchHistoryStyleCell) { // 普通风格Cell
        [self.tableView reloadData];
    } else { // 搜索历史为标签
        // 更新
        self.searchHistoryStyle = self.searchHistoryStyle;
    }
    // 保存搜索信息
    [NSKeyedArchiver archiveRootObject:self.searchHistories toFile:PYSearchHistoriesPath];

    // 如果代理实现了代理方法则调用代理方法
    if ([self.delegate respondsToSelector:@selector(searchViewController:didSearchWithsearchBar:searchText:)]) {
        [self.delegate searchViewController:self didSearchWithsearchBar:searchBar searchText:searchBar.text];
        return;
    }
    // 如果有block则调用
    if (self.didSearchBlock) self.didSearchBlock(self, searchBar, searchBar.text);
}
ko1o commented 7 years ago

@SHRemover 更新最新版本测试!

SHRemover commented 7 years ago

ok~