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 9255497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:43:51+00:00 2026-06-18T11:43:51+00:00

I have code that runs in searchBarCancelButtonClicked: I want to run the same code

  • 0

I have code that runs in searchBarCancelButtonClicked: I want to run the same code when the user clicks away from the searchbar, even though cancel isn’t necessarily clicked. My current code is below but has an issue that I can’t figure out. I have placed a UIView underneath the search bar that when clicked runs a method that does what I want.

The issue is that when the searchbar is active, the semi-transparent view associated with uisearchbar comes up on top of my view and clicking the view still just dismisses the searchbar, but doesn’t run my method. After the searchbar is dismissed, clicking the view does run my method so I know that is ok. Basically I need to be able to make the view gesture active while the searchbar is the first responder.

- (BOOL)searchBarShouldBeginEditing:(UISearchBar*)searchBar {
    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSearch:)];
    UIView *transparentView = [[UIView alloc]initWithFrame:transparentViewRect];
    [transparentView setBackgroundColor:[UIColor blackColor]];
    [transparentView addGestureRecognizer:singleTap];
    [self.view addSubview:transparentView];
    [self.view bringSubviewToFront:transparentView];

    return  YES;

}

- (void) dismissSearch:(UITapGestureRecognizer *)tapGesture
{
  //Run my code
}
  • 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-18T11:43:52+00:00Added an answer on June 18, 2026 at 11:43 am

    I guess you can probably use the searchBarShouldEndEditing: or searchBarTextDidEndEditing: delegate methods…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that runs when a user clicks anywhere in the body
Basically when a user clicks a button I have a javascript code that runs
I have code that I run when my form runs (I tried below InitializeComponent();
I have a few lines of code that I want to run asynchronously in
I want to have code that runs as efficiently as possible. I have views
I have a code that runs to select a date from calender, but I
I have some code that runs a model in a loop. Each iteration of
I have this code that runs but never stops. class A { public static
below i have a code that runs in most of my simple programs ..
I have some jQuery code that runs fine until I add the jQuery UI

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.