0

How do I detect when a user types into a UISearchBar? Should be really easy. Cannot find any help in the Class Reference. Is not this supposed to print?

func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool{
    println("Started Editin'...")
    return true
}
tika
  • 7,135
  • 3
  • 51
  • 82

2 Answers2

1

That would be because it is the responsibility of the UISearchBarDelegate to inform you of the text changing in a UISearchBar.

UISearchBarDelegate

thatidiotguy
  • 8,701
  • 13
  • 60
  • 105
1

You have a good question, I struggled with a similar one in the past. @thatidiotguy is correct, you're going to need to implement the UISearchBarDelegate in order to be notified.

I believe the method that you're looking for is: filterContentForSearchText. It's a UISearchBarDelegate method that will send all the text in the box to this method each time you type or delete a character.

This S.O. question may shed a little more light on your question: Click Here

Best of luck!
Kyle

Community
  • 1
  • 1
kbpontius
  • 3,867
  • 1
  • 30
  • 34
  • Can you suggest how the method works? With Code example, if possible. – tika Feb 13 '15 at 19:10
  • The code examples can be rather in-depth, can I refer you to this tutorial? It will help you get the full idea, in context: http://www.appcoda.com/search-bar-tutorial-ios7/ Please let me know if you have any other questions. – kbpontius Feb 13 '15 at 19:13