मेरा ऐप एक UISearchDisplayController
का उपयोग करता है। उपयोगकर्ता एक खोज पद में प्रवेश किया है जब मैं यह searchbar तक दिखाई दे करना चाहते हैं। यह काम करता है उपयोगकर्ता का मिलान परिणामों में से एक चुनता है, लेकिन उपयोगकर्ता नहीं 'खोज' बटन पर क्लिक करता है, तो यदि।खोज पद दृश्यमान रखें जब 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:
में ऐसा ही करते पाठ searchbar में नहीं रहता। इस स्थिति में मैं इसे कैसे पूरा कर सकता हूं इस पर कोई विचार?
संबंधित, अगर मैं सर्चबार का टेक्स्ट सेट करता हूं (लेकिन UISearchDisplayController
निष्क्रिय) छोड़ देता है तो यह SearchResultsTableView का प्रदर्शन ट्रिगर करता है। मैं केवल यह दिखाना चाहता हूं कि जब उपयोगकर्ता खोजबार पर टैप करता है।
संपादित करें: किसी भी समय searchResultsTableView दिखाए बिना एक searchbar का पाठ सेट करने के लिए एक समाधान मिल गया:
// 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: नहीं एनिमेटेड: हाँ]; self.searchController.searchBar.text = searchBar.text; 'लेकिन स्पष्ट रूप से' searchBar.text' अब और नहीं है जो मैंने सोचा था कि यह खोज बार खाली करने के लिए 'setActive' विधि' के कारण था। –