2

I have a class and use UICollectionViewController, UICollectionViewDelegateFlowLayout , UISearchBarDelegate

I want use searchbar in Navigation View , but when I clicked on Cancel Button or SearchButton , searchBarSearchButtonClicked and searchBarCancelButtonClicked , non of them was called.

but I use this function and this func was called :

func searchBar(searchBar: UISearchBar, textDidChange searchText:        String) {
    println("search is working ")
}

this is my viewDidload func:

 override func viewDidLoad() {

    super.viewDidLoad()   

    let searchBar = UISearchBar()
    searchBar.delegate = self
    searchBar.sizeToFit()
    navigationItem.titleView = searchBar

}

and this is search and cancel func:

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    println("cancel button called")
}

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
    println("search button called")

}

So , what is wrong? searchBar func is called when I write something in searchbar but when click on searchButton and cancel button nothing happen!?

1 Answer 1

4

I use simulator iphone ,So search button is enter button of keyboard but I used another button , then nothing happen. now I use enter , and every thing is ok. this is very funny!:D

Sign up to request clarification or add additional context in comments.

3 Comments

Hilarious, I was trying to click the magnifying glass.
yeah...same happened to me
i face same problem, cancel button is working when keyboard is active and if keyboard is hide than search cancel button doesn't work for me. is it possiable search cancel button working with keyboard will be hidden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.