samoye
samoye

Reputation: 73

iOS: How can I judge the state of UISearchBar?

As the bellow pics: There are 2 states for UISearchBar, how can I judge the searchBar's state?

  1. 1th

The 1th state

  1. 2th

The 2th state

Upvotes: 1

Views: 291

Answers (2)

Murat Tezyapar
Murat Tezyapar

Reputation: 142

I think searchBar.isFirstResponder is the property you're looking for.

Upvotes: 1

Aris Guimerá
Aris Guimerá

Reputation: 1017

On Swift I use this, I'm sure have anything like that to obj-c

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    searchActive = true;
}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
    searchActive = false;
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    searchActive = false;
}

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
    searchActive = false;
}

Upvotes: 2

Related Questions