3

I am using a UISearchBar, with the search bar I am using the default UIKeyboard. When the user types using the keyboard as soon as one character has been entered the search button appears active.

I would like to know if there is a way to make it so that the search button does not become active until two characters have been entered?

The major issue I am having here is that I don't know how to access this function of the UIKeyboard and am hoping someone can either point me to a reference or show me some example code.

John Topley
  • 113,588
  • 46
  • 195
  • 237
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
  • I found that you can get the displayed keyboard object but the private methods responsible for the returnKey state do not take effect at searchbar delegate methods, the searchbar might update the button state after the delegate method are called. Anyway that was just an exercise, you could not use such a code in the productive version. – A-Live Sep 11 '12 at 03:57
  • okay.. thanks for checking up for me.. Thats a real pain.. why would they not allow you to set it yourself.. I will keep looking for alternatives.. but sounds like you've done enough research for the both of us. :P – HurkNburkS Sep 11 '12 at 04:20
  • Oh, i have an alternative, why use standard keyboard when you can create your own ? It might be unique and fancy, the only disadvantages is that you'll also have to work on textView-keyboard communication and there's a problem with localizations support. On the other hand that is a separate yet reusable project :) – A-Live Sep 11 '12 at 04:24
  • haha, yea thanks for the suggestion.. Will have to think about it... could be a big undertaking and I don't nessacerally have that time available... but it might be a case where I have to :( – HurkNburkS Sep 11 '12 at 20:28

1 Answers1

0

You can't disable the button, but if you implement the searchbar's delegate you can override the searchBarSearchButtonClicked: method, and stop the searchbar button from searching below a certain range of characters.

Check out the answer here:

https://stackoverflow.com/a/9722139/951830

Community
  • 1
  • 1
Robotnik
  • 3,643
  • 3
  • 31
  • 49
  • Okay yes this works well.. The only thing it is missing for what I am trying to achieve is the button turns blue after only one character entry.. I am trying to prevent this from turning blue until the second character is entered. Thank you very much for your response.. – HurkNburkS Sep 11 '12 at 03:54