This Is
This Is

Reputation: 137

How do you activate a UISearchDisplayController when a button is clicked

I have this UISearchDisplayController and so far it can only be activated (ready to type with a drop down searchresulttableview) when someone clicks the UISearchBar. Is there a way to make a button do this task? I will appreciate any answer I receive.

Upvotes: 2

Views: 707

Answers (3)

Daniel Larsson
Daniel Larsson

Reputation: 6394

Since UISearchBar extends UIResponder just like a UITextField, you can simply call becomeFirstResponder on the search bar to give it focus.

[button addTarget:self action:@selector(clickedSearchBar) forControlEvents:UIControlEventTouchUpInside];

- (void)clickedSearchBar {
    [searchDisplayController.searchbar becomeFirstResponder];
}

Upvotes: 1

rmaddy
rmaddy

Reputation: 318824

Look at the docs for UISearchDisplayController. There is an active property and a setActive:animated: method.

Have your button action call this:

[theSearchController setActive:YES animated:YES];

Upvotes: 2

UnsafePointer
UnsafePointer

Reputation: 736

Have you tried [searchDisplayController.searchbar becomeFirstResponder] inside your button selector?

Upvotes: 3

Related Questions