Learn-iOS-Swift-by-Examples/UICatalog/Swift/UIKitCatalog/SearchBarEmbeddedInNavigati...

43 lines
1.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
A view controller that demonstrates how to present a search controller's search bar within a navigation bar.
*/
import UIKit
class SearchBarEmbeddedInNavigationBarViewController: SearchControllerBaseViewController {
// MARK: - Properties
// `searchController` is set in viewDidLoad(_:).
var searchController: UISearchController!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
// Create the search results view controller and use it for the `UISearchController`.
let searchResultsController = storyboard!.instantiateViewControllerWithIdentifier(SearchResultsViewController.StoryboardConstants.identifier) as! SearchResultsViewController
// Create the search controller and make it perform the results updating.
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.searchResultsUpdater = searchResultsController
searchController.hidesNavigationBarDuringPresentation = false
/*
Configure the search controller's search bar. For more information on
how to configure search bars, see the "Search Bar" group under "Search".
*/
searchController.searchBar.searchBarStyle = .Minimal
searchController.searchBar.placeholder = NSLocalizedString("Search", comment: "")
// Include the search bar within the navigation bar.
navigationItem.titleView = searchController.searchBar
definesPresentationContext = true
}
}