选择搜索栏导致表视图和搜索栏消失

时间:2020-04-13 19:08:17

标签: ios swift uisearchbar uisearchcontroller

我为另一个应用程序使用了非常相似的代码,并且搜索栏的行为应达到预期。由于某些原因,下面的这段代码不适用于我当前的应用。在线搜索没有得到任何答案。委托函数并不是造成这种情况的原因,因为当我注释掉所有代码时,它会导致完全相同的行为。实际上,当我在下面注释掉大部分代码时,它会导致相同的行为。我不知道为什么点击搜索会破坏我的用户界面。我想念什么吗?我一定是...

private func configureSearchBar() {
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.showsCancelButton = true
    searchController.searchBar.delegate = self
    searchController.searchBar.isUserInteractionEnabled = true
    definesPresentationContext = true
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(searchController.searchBar)
    searchController.searchBar.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
    searchController.searchBar.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true
    searchController.searchBar.heightAnchor.constraint(equalToConstant: 55).isActive = true
    searchController.searchBar.topAnchor.constraint(equalTo: agendaLabel.bottomAnchor, constant: 8).isActive = true
    let color:UIColor = .journeyGold
    let lightGold = color.withAlphaComponent(0.5)
    searchController.searchBar.tintColor = lightGold
    searchController.searchBar.barTintColor = lightGold
    searchController.searchBar.backgroundColor = lightGold
    searchController.searchBar.layer.borderColor = lightGold.cgColor
    navigationItem.hidesSearchBarWhenScrolling = false
    searchController.hidesNavigationBarDuringPresentation = true
    searchController.searchBar.text = ""
    searchController.searchBar.setShowsCancelButton(true, animated: false)
}

0 个答案:

没有答案
相关问题