UITableViewController与Swift 4中UIViewController中的UISearchController的SearchBar重叠

时间:2017-12-14 10:04:39

标签: ios swift uitableview uisearchcontroller

我正在将UISearchControllerUITableViewController整合到ViewController中。

以下是我实施的代码:

func configureSearchController() {

    let searchTableViewController = UITableViewController()

    self.searchController = UISearchController(searchResultsController: searchTableViewController)

    self.searchController.searchResultsUpdater = self;

    self.searchController.hidesNavigationBarDuringPresentation = false

    self.searchController.searchBar.searchBarStyle = .default

    self.navigationItem.titleView = self.searchController.searchBar
    self.searchController.searchBar.becomeFirstResponder()
    self.searchController.searchBar.placeholder = "Title"

    let searchBar = self.searchController.searchBar

    if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
        textfield.textColor = UIColor.black
        if let backgroundview = textfield.subviews.first {

            // Background color
            backgroundview.backgroundColor = UIColor.white

            // Rounded corner
            backgroundview.layer.cornerRadius = 5
            backgroundview.clipsToBounds = false
        }
    }

    self.definesPresentationContext = true

    // Setting delegates and other stuff
    searchTableViewController.tableView.dataSource = self
    searchTableViewController.tableView.delegate = self
    self.searchController.delegate = self


    self.searchController.dimsBackgroundDuringPresentation = true
    self.searchController.searchBar.delegate = self
}

现在问题是,当我开始输入SearchBar TableViewController出现在SearchBar时。

如何在SearchBarTableViewController之间添加空格?

它的外观如下:

enter image description here

0 个答案:

没有答案