Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build An iTunes Search App Building the User Interface Implementing a Search Bar

Christian A. Castro
Christian A. Castro
30,501 Points

Implementing a Search Bar, Building an iTunes Search App! Any idea why the keyboard is not coming up on my end?

Here's my code:

import UIKit

class SearchResultsController: UITableViewController
{

    let searchController = UISearchController(searchResultsController: nil)

    override func viewDidLoad()
    {
        super.viewDidLoad()


        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector (SearchResultsController.dismissSearchResultsController))

        tableView.tableHeaderView = searchController.searchBar
        //Dismissing backGround..
        searchController.dimsBackgroundDuringPresentation = false
        //Responsible for updating the content..
        searchController.searchResultsUpdater = self
    }

    @objc func dismissSearchResultsController()
  {
    //This dismiss the viewController..
    self.dismiss(animated: true, completion: nil)

  }

}

extension SearchResultsController: UISearchResultsUpdating
{
    func updateSearchResults(for searchController: UISearchController)
    {
        print(searchController.searchBar.text!)
    }
}

1 Answer

Christian A. Castro
Christian A. Castro
30,501 Points

Nevermind! I was able to figure out! If any of your experience the same issue, press on your computer: Command + K, and it will bring it up in iOs Simulator. From that point forward, every single time you click on the search bar; it will show it up automatically!!

Hope this helps someone out there!

Amaury,

Xavier D
Xavier D
Courses Plus Student 5,840 Points

I agree. Alternately, you can use the simulator's Hardware menu to toggle the Keyboard options.