Search code examples
iosswiftuisearchbaruikeyboardprogrammatically-created

Why is there a UIToolbar left behind after resigning keyboard from search bar?


This is programmatically made by the way. I added a UISearchBar to a Navigation Title View. It becomes first responder when the controller first loads. The cancel button from the search bar when clicked removes the keyboard and goes back to root view controller. When that happens a UIToolbar is left behind with a significant blur on top of the whole UIToolBar view. I've inspected it through the View Hierarchy and it shows it is a Toolbar left behind from I think the keyboards bottom view where the emoji button and voice buttons are. I've tried resigningFirstResponder, and endEditing(true). Both still leave behind the toolbar which I never created in my app. Any recommendations on how to fix it, or is it a bug that is out of my control?

Implementation,

// Setup for viewDidLoad
    private func setup() {
        // Navigation
        navigationController?.setToolbarHidden(false, animated: true)
        navigationItem.setHidesBackButton(true, animated: false)
        searchView.searchBar.delegate = self
        navigationItem.titleView = searchView.searchBar
        searchView.searchBar.becomeFirstResponder()
    }

    // When the cancel button is pressed
    public func goBackToRootController() {
        // I've used both individually and together and the problem still occurs
        searchView.searchBar.resignFirstResponder()
        searchView.searchBar.endEditing(true)
        navigationController?.popToRootViewController(animated: true)
    }


Solution

  • Issue Fixed - The setToolBarHidden() method was set to false. Which enables or shows the Toolbar throughout the Application.