ios - UISearchDisplayController: Cancel as dismiss button -


I have this problem with UISearchDisplayController . I want to use it in a dedicated view to handle searches. For my controller class I used the structure of the search bar, search controller and a table widget controller. SearchViewController is linked to a .xib @interface SearchViewController: UIViewController & lt; UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDelegate, UITableViewDataSource & gt; {NSSAT * word; UISearchDisplayController * searchController; UISearchBar * searchBar; PhraseTab Viewer Controller * Phrase Touview Viewer; }

As soon as SearchViewController appears, searchbar becomes the first sender and search is therefore active. One exception: To return to the previous view, I want to use the Cancel button for searchbar. Now here's the problem: If any underlying table touches the gray area of ​​the view, when no one is searching, the cancel button (and therefore the only way to go back) disappears.

Here's the thing I've tried to solve:

  1. Shows the kernel button = yes on searchDisplayControllerDidEndSearch . Works, but the resulting UI is ugly in the form of a pulse: the button of the cancel button reappears again.
  2. Add UITapGestureRecognizer in the search controller's searchResultTableView is not expected to capture the tap, it still goes.
  3. Subject UISearchBar and override set to self.searchController.searchBarShowsCancelButton: - did not work.

    How to solve the idea:

    1. Always hide the cancel button and add a custom button instead. Q: Do you have an idea how to do this Does the UI look good? What is the need to worry about handling all the cases, as the search-text field always keeps well on the edge of the button.
    2. For a more flexible solution, UISearchDisplayController do you know where to look? Pre-iOS 3 This controller did not exist, is not it? Are not you still working there?

      I'm glad to have any input for you in advance thanks.

      OK I think I found a way that works: I just navigate the navigation bar For the right kind of event such as the user gets the back button, see the corresponding code below, although I must add something that some event handling is part of the solution for other "special" behaviors of UISearchDisplayController , which is the navigation The bar appears again at the wrong time (before jumping one expansion Ge which will cause ugly animation).

      EDIT: And yes I know that this is ugly - but it is such that if you ask me very little UISearchDisplayController static BOOL _cancelBtnClicked = no; Static BOOL _phraseClicked = No; - (empty) SearchBarbonButtoned: (UISearchBar *) _Searchbar {if (Self .searchController.active) {_cancelBtnClicked = YES; } And {[self-back]; }} - (zero) searchDisplayControllerDidEndSearch: (UISearchDisplayController *) controller {if (_cancelBtnClicked) {_cancelBtnClicked = NO; [Self back]; } And if (! _phraseClicked) {[Self. Navigation controller set navigation bar: no animated: yes]; }} - (zero) keyboard hahahahid: (nsnification *) notification {if (_phraseClicked) {_phraseClicked = NO; } And if (i.e. ICIV loaded & selfview.indo! = Void) {self.navigationController.navigationBar.hidden = YES; }} - Hide (null) Newspaper Endpoint {self.navigationController.navigationBar.hidden = YES; [[NSNotificationCenter defaultCenter] addObserver: Self Selector: @Sylector (KeyboardDialHide :) Name: UIKeyboardWillHideNotification Object: Zero]; } - (zero) table view: (UITableView *) table view was SelectionRowAtIndexPath: (NSIndexPath *) indexPath {_phraseClicked = YES; [Self.phraseTableViewController TableView: Table Selection RowAtIndexPath: indexPath]; }

Comments