chogath chogath - 1 year ago 154
Objective-C Question

UISearchController like Maps of Apple

I'm developing an iOS app using Objective C.
I implemented UISearchController , It works fine I just wanted to be like Maps of Apple but it's not the case the buttons on the navigation bar doesn't disappear
here is some screenshot .

Any ideas ?!

Before click

After click

Answer Source

Try to use the delegate method of UISearchBar like this

On begin editing of UISearchBar remove the Navigation button like this

func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
    self.navigationItem.leftBarButtonItem = nil
    self.navigationItem.rightBarButtonItem = nil
    return true

On cancel button click add the navigation button again

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    //Add the code you are using to previously set navigation with buttons and UISearchBar

Hope this will help you.