iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UISearchBarDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UISearchBarDelegate

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 * _Nonnull)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.

    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 * _Nonnull)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Discussion

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

    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 * _Nonnull)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.

    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 * _Nonnull)searchBar

    Parameters

    searchBar

    The search bar that was tapped.

    Availability

    Available in iOS 3.2 and later.