Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

搜索建议返回界面消失 #231

Open
xiuqiao opened this issue Jul 19, 2019 · 0 comments
Open

搜索建议返回界面消失 #231

xiuqiao opened this issue Jul 19, 2019 · 0 comments

Comments

@xiuqiao
Copy link

xiuqiao commented Jul 19, 2019

问题描述

自定义搜索建议的 cell,选中进入后返回导致搜索建议消失

原因

1,在选中建议时会设置 searchBar.text 为 textLabel.text 自定义cell 不一定设置cell默认textLabel
#pragma mark - UITableViewDelegate

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.searchBar.text = cell.textLabel.text;

    if ([self.delegate respondsToSelector:@selector(searchViewController:didSelectSearchHistoryAtIndex:searchText:)]) {
    [self.delegate searchViewController:self didSelectSearchHistoryAtIndex:indexPath.row searchText:cell.textLabel.text];
    [self saveSearchCacheAndRefreshView];
    } else {
    [self searchBarSearchButtonClicked:self.searchBar];
    }
    }

2,在返回刷新数据的时候会根据 !self.searchBar.text.lengt 来决定是否隐藏 searchSuggestionView,这个时候 searchBar.text 被设置为空了,,,,

  • (NSInteger)searchSuggestionView:(UITableView *)searchSuggestionView numberOfRowsInSection:(NSInteger)section
    {
    if ([self.dataSource respondsToSelector:@selector(searchSuggestionView:numberOfRowsInSection:)]) {
    NSInteger numberOfRow = [self.dataSource searchSuggestionView:searchSuggestionView numberOfRowsInSection:section];
    searchSuggestionView.hidden = self.searchSuggestionHidden || !self.searchBar.text.length || 0 == numberOfRow;
    self.baseSearchTableView.hidden = !searchSuggestionView.hidden;
    return numberOfRow;
    }
    return self.searchSuggestions.count;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant