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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:19:26+00:00 2026-05-21T22:19:26+00:00

My App is having a search bar for searching records from the table view,which

  • 0

My App is having a search bar for searching records from the table view,which is populated by sqlite DB.
My problem is that when the view opens the “cancel” button is not enabled and also I cant touch on that, just like a image only.It is there but no action is with that.
when we click on that search bar text the cancel button will be changed to “done” it is enabled one.
so here is my code

this is my search bar view,see that cancel button.It is not enabled

this is my search bar view.see that cancel button.It is not enabled

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    //[newSearchBar setShowsCancelButton:YES animated:YES];


    newSearchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

    NSLog(@"search begin edit") ;

    //searchString = searchBar.text;

    //NSLog(@"print did edit searchstring : %@", searchString) ;

    for(UIView *view in [searchBar subviews])       
    {

        //shareItemId =newSearchBar.text;

        if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
            [(UIBarItem *)view setTitle:@"Done"];

        }
        }

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    NSLog(@"searchBarTextDidEndEditing:");


    [searchBar resignFirstResponder];
    //[self dismissModalViewControllerAnimated:YES];
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    NSLog(@"searchBarSearchButtonClicked");


    searchString = searchBar.text;
    NSLog(@"search %@", searchBar.text);
    [newSearchBar setShowsCancelButton:NO animated:YES];

    [searchBar resignFirstResponder];
    //[self dismissModalViewControllerAnimated:YES];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

{  
    NSLog(@" searchBarCancelButtonClicked");


    [searchBar resignFirstResponder];

     shareItemName =newSearchBar.text;

    [self dismissModalViewControllerAnimated:YES];

}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

    NSLog(@"searchBarShouldBeginEditing");


    [newSearchBar setShowsCancelButton:YES animated:YES];
    return YES;
}

These are my delegates for that

Please check my code and give me the answer. I need to enable the “Cancel” button when the view is loaded and it action will be go back to previous view

I need like this

enter image description here

Or else how can I add a another cancel button on exciting cancel button.so that I can enable that.please give me all the details

  • 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-05-21T22:19:27+00:00Added an answer on May 21, 2026 at 10:19 pm

    My guess is that Apple made the UISearchBar in a way that the cancel button is disabled if the search text field is empty or not first responder.

    This is make sense because you should not use the “Cancel” button to other purpose than actually canceling the search. and since there is no search to cancel – the button is disabled.

    If you still want that the button will be active immediately when the view is presented, you can call at viewWillAppear: to [mySearchBar becomeFirstResponder];

    This will cause to the keyboard to appear and the button will be enabled.
    And then if the user hit cancel you can intercept it to go back to the previous view. (I’m not sure if apple will like this behavior).

    Sample code:

    -(void) viewWillAppear : (BOOL) animated
    {
        [super viewWillAppear:animated];
        // Make keyboard pop and enable the "Cancel" button.
        [self.mySearchBar becomeFirstResponder];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an app that is having a UIWebView which contains an advert.
Im having a problem with my app that causes it to crash when no
So I'm having trouble implementing a search bar in my app. The methods find
I'm having some trouble searching a SQLite database in my Android app. I use
My iphone App shows a table view having list of 6000 items. (these items
I am having a problem placing a tool bar in the root view controller
Possible Duplicate: Hide facebook app from search Okay, I know that this question was
I am trying to accomplish this: Consider a table view with Search Bar on
I have a huge web app that is having issues with memory leak in
Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in

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.