Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using UISearchBar in my code. I have imported its delegate in header file and implemented some delegate methods in implementation file also.

When we tap on the UISearchBar, a keyboard will appear to enter text. The return key of the keyboard is "Search" button. It will disabled by default. When we enter a character, It will get enabled. (Am I right?)

Here the problem comes.. I want to enable the UISearchBar keyboard's return key when the user types atleast two letters.

Is it possible? If yes, how can we do it?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
478 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can't disable the search button. What you can do is use the UISearchBarDelegate methods to figure out if you should take action on the search button being clicked, like so:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    if (searchBar.text.length < 2) {
        return;
    }
    else {
        // Do search stuff here
    }
}

The Apple Documentation for this is very useful as well, and is a great starting point for customizing the searchBar's behavior.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...