iOS Developer Library

Developer

UIKit Framework Reference UISearchBarDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UISearchBarDelegate

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

The UISearchBarDelegate protocol defines the optional methods you implement to make a UISearchBar control functional. A UISearchBar object provides the user interface for a search field on a bar, but it’s the application’s responsibility to implement the actions when buttons are tapped. At a minimum, the delegate needs to perform the actual search when text is entered in the text field.

  • Tells the delegate that the bookmark button was tapped.

    Declaration

    Swift

    optional func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar)

    Objective-C

    - (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Discussion

    There is no automatic bookmark support provided by the search bar. It’s the application’s responsibility to implement this method to perform some action if the bookmark button is tapped by the user.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the cancel button was tapped.

    Declaration

    Swift

    optional func searchBarCancelButtonClicked(_ searchBar: UISearchBar)

    Objective-C

    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Discussion

    Typically, you implement this method to dismiss the search bar.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the search button was tapped.

    Declaration

    Swift

    optional func searchBarSearchButtonClicked(_ searchBar: UISearchBar)

    Objective-C

    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Discussion

    You should implement this method to begin the search. Use the text property of the search bar to get the text. You can also send becomeFirstResponder to the search bar to begin editing programmatically.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the search results list button was tapped.

    Declaration

    Swift

    optional func searchBarResultsListButtonClicked(_ searchBar: UISearchBar)

    Objective-C

    - (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.