내 앱은 UISearchDisplayController
을 사용합니다. 사용자가 검색어를 입력하면 검색 창에 계속 표시되기를 원합니다. 사용자가 일치하는 결과 중 하나를 선택했지만 사용자가 '검색'버튼을 클릭하지 않으면이 방법이 작동합니다.UISearchDisplayController가 비활성 상태 일 때 검색어를 계속 표시합니다.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSString *selectedMatch = [self.searchMatches objectAtIndex:indexPath.row];
[self.searchDisplayController setActive:NO animated:YES];
[self.searchDisplayController.searchBar setText:selectedMatch];
return;
}
...
을하지만 -searchBarSearchButtonClicked:
에서 같은 일을 할 경우 텍스트가 검색 창에 남아 있지 않습니다
이 작동합니다. 이 상황에서 내가 이것을 어떻게 달성 할 수 있을지에 대한 아이디어가 있습니까?
관련하여 검색 바의 텍스트를 설정했지만 (UISearchDisplayController
은 비활성 상태로 유지) searchResultsTableView의 표시를 트리거합니다. 사용자가 검색 창을 탭했을 때만 표시하고 싶습니다.
편집 : 해결 언제든지 searchResultsTableView을 표시하지 않고 검색 창의 텍스트를 설정하는 찾았
// This hacky YES NO is to keep results table view hidden (animation required) when setting search bar text
[self.searchDisplayController setActive:YES animated:YES];
[self.searchDisplayController setActive:NO animated:YES];
self.searchDisplayController.searchBar.text = @"text to show";
더 나은 제안이 여전히 환영!
아 감사합니다! 나는'[self.searchController setActive : NO animated : YES];를하고 있었다. self.searchController.searchBar.text = searchBar.text;'분명히'searchBar.text'는 검색 막대를 비우는'setActive' 메쏘드 때문이라고 생각했습니다. –