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

39 lines
1.3 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 show search results from a search controller within the source view controller (in this case, in the table view's header view).
*/
import UIKit
class SearchShowResultsInSourceViewController: SearchResultsViewController {
// MARK: - Properties
// `searchController` is set in `viewDidLoad(_:)`.
var searchController: UISearchController!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
/*
Create the search controller, but we'll make sure that this
`SearchShowResultsInSourceViewController` performs the results updating.
*/
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
// Make sure the that the search bar is visible within the navigation bar.
searchController.searchBar.sizeToFit()
// Include the search controller's search bar within the table's header view.
tableView.tableHeaderView = searchController.searchBar
definesPresentationContext = true
}
}