Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8197873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:49:52+00:00 2026-06-07T05:49:52+00:00

I have this problem with UISearchDisplayController . I want to use it in a

  • 0

I have this problem with UISearchDisplayController. I want to use it in a dedicated view for handling searches. For my controller class I used a composition of the searchbar, the searchcontroller and a tableviewcontroller. SearchViewController is linked to a .xib.

@interface SearchViewController : UIViewController <UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDelegate, UITableViewDataSource> {
  NSSet *words;
  UISearchDisplayController *searchController;
  UISearchBar *searchBar;
  PhraseTableViewController *phraseTableViewController;
}

As soon as SearchViewController appears, the searchbar becomes firstresponder and the search is therefore active. Everything looks and works fine, with one exception:
In order to get back to the previous view, I want to use the cancel button of the SearchBar. Now here comes the problem: If the user touches the grey area of the underlying tableview when no search has been made, the cancel button (and therefore the only way to get back) disappears.

Here’s the thing I’ve tried to solve this:

  1. showsCancelButton = YES on searchDisplayControllerDidEndSearch. Works, but the resulting UI is ugly as hell: The cancel button transitions out and then reappears.
  2. Add a UITapGestureRecognizer to the searchcontroller’s searchResultTableView in the hope to catch the tap. Doesn’t work, it still goes through.
  3. Subclass UISearchBar and override self.searchController.searchBar setShowsCancelButton: – Didn’t work.

Ideas how to solve this:

  1. Always hide the cancel button and instead add a custom button. Question: Do you have an idea how to do this such that the UI looks good? What concerns me most is to handle all the cases such that the search-textfield always keeps nicely at the side of the button.
  2. Ditch UISearchDisplayController all together for a more flexible solution. Do you know where to look? Pre-iOS 3 this controller didn’t exist, right? Aren’t there solutions around that still work?

I’m glad for any input of yours. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:49:53+00:00Added an answer on June 7, 2026 at 5:49 am

    Ok I think I’ve found a way that works: I just unhide the navigation bar for the right kind of event such that the user gets a back button. See the relevant code below, however I must add that some of the event handling is part of the solution for other “special” behaviors of UISearchDisplayController that make the navigation bar reappear at the wrong times (before jumping to a detail page which would also lead to ugly animations).

    Edit: And yes I know it’s ugly – but so is that damn UISearchDisplayController if you ask me.

    static BOOL _cancelBtnClicked = NO;
    static BOOL _phraseClicked = NO;
    
    - (void)searchBarCancelButtonClicked:(UISearchBar *)_searchBar{ 
      if(self.searchController.active){
        _cancelBtnClicked = YES;
      }else{
        [self back];
      }
    }
    
    - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
      if(_cancelBtnClicked){
        _cancelBtnClicked = NO;
        [self back];
      }
      else if (!_phraseClicked) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
      }
    }
    
    - (void)keyboardWillHide:(NSNotification *)notification {
      if (_phraseClicked) {
        _phraseClicked = NO;
      }
      else if(self.isViewLoaded && self.view.window != nil) {
        self.navigationController.navigationBar.hidden = YES;
      }
    }
    
    - (void)hideNavbarAndKeepHidden {        
      self.navigationController.navigationBar.hidden = YES;
      [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];   
    }
    
    -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      _phraseClicked = YES;
      [self.phraseTableViewController tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem with my view-controller relation. This is the controller: <?php class
I have this problem: I want to generate a new source code file from
I have this problem since I'm beginning in OOP programming I want to close
I have this problem in my SlashDot Menu. I want to change the picture
I have this problem. Session does not work when I use with $_POST. If
i have this problem: starting from an empty list (0 elements) i want check
I have this problem. I have a module (module 1) that use Nhibernate to
I have this problem: I have a vb.net class (visual studio 2010) : ....
I have this problem. I have a graph of n nodes that I want
I have this problem: $id is id for each user $img = 'http://www.somesite.com/pictures/'; $no_img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.