Protocol: UISearchBarDelegate

Overview

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 scope button selection changed.Ask the delegate if text in a specified range should be replaced with given text.Tells the delegate that the user changed the search text.Tells the delegate that the bookmark button was tapped.Tells the delegate that the cancel button was tapped.Tells the delegate that the search results list button was tapped.Tells the delegate that the search button was tapped.Asks the delegate if editing should begin in the specified search bar.Asks the delegate if editing should stop in the specified search bar. Tells the delegate when the user begins editing the search text.Tells the delegate that the user finished editing the search text.

Instance Method Summary (collapse)

Instance Method Details

- (Object) searchBar(searchBar, selectedScopeButtonIndexDidChange:selectedScope)

Tells the delegate that the scope button selection changed.

Parameters:

  • searchBar (UISearchBar)

    The search bar that was tapped.

  • selectedScope (Integer)

    The index of the selected scope button (see selectedScopeButtonIndex).

Returns:

- (Boolean) searchBar(searchBar, shouldChangeTextInRange:range, replacementText:text)

Ask the delegate if text in a specified range should be replaced with given text.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

  • range (NSRange)

    The range of the text to be changed.

  • text (String)

    The text to replace existing text in range.

Returns:

  • (Boolean)

    YES if text in range should be replaced by text, otherwise, NO.

- (Object) searchBar(searchBar, textDidChange:searchText)

Tells the delegate that the user changed the search text. This method is also invoked when text is cleared from the search text field.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

  • searchText (String)

    The current text in the search text field.

Returns:

- (Object) searchBarBookmarkButtonClicked(searchBar)

Tells the delegate that the bookmark button was tapped. 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.

Parameters:

  • searchBar (UISearchBar)

    The search bar that was tapped.

Returns:

- (Object) searchBarCancelButtonClicked(searchBar)

Tells the delegate that the cancel button was tapped. Typically, you implement this method to dismiss the search bar.

Parameters:

  • searchBar (UISearchBar)

    The search bar that was tapped.

Returns:

- (Object) searchBarResultsListButtonClicked(searchBar)

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

Parameters:

  • searchBar (UISearchBar)

    The search bar that was tapped.

Returns:

- (Object) searchBarSearchButtonClicked(searchBar)

Tells the delegate that the search button was tapped. 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.

Parameters:

  • searchBar (UISearchBar)

    The search bar that was tapped.

Returns:

- (Boolean) searchBarShouldBeginEditing(searchBar)

Asks the delegate if editing should begin in the specified search bar.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

Returns:

  • (Boolean)

    YES if an editing session should be initiated, otherwise, NO.

- (Boolean) searchBarShouldEndEditing(searchBar)

Asks the delegate if editing should stop in the specified search bar.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

Returns:

  • (Boolean)

    YES if editing should stop, otherwise NO.

- (Object) searchBarTextDidBeginEditing(searchBar)

Tells the delegate when the user begins editing the search text.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

Returns:

- (Object) searchBarTextDidEndEditing(searchBar)

Tells the delegate that the user finished editing the search text. Typically, you implement this method to perform the text-based search.

Parameters:

  • searchBar (UISearchBar)

    The search bar that is being edited.

Returns: