UISearchController以模态方式存在时的错误行为

时间:2016-09-18 11:36:36

标签: ios uitableview uiviewcontroller swift3 uisearchcontroller

我向UIViewController展示了模态风格。 UIViewControllerUITableView。我将UISearchController添加到UITableView,但UISearchController在消失时行为不正确。我多次UISearchControllers,但我没有面对这种行为。

我的代码

所以我展示了UIViewController

 @objc fileprivate func selectInterlocutor(_ button: UIButton) {
        let selectInterlocutorTVC = SelectInterlocutorTableViewController()
        selectInterlocutorTVC.modalPresentationStyle = .overCurrentContext
        selectInterlocutorTVC.modalTransitionStyle = .coverVertical
        selectInterlocutorTVC.providesPresentationContextTransitionStyle = true
        present(selectInterlocutorTVC, animated: true) {

        }
    }

我将UISearchController添加到tableView

  fileprivate func addSearchController() {
        searchController.searchBar.barStyle = .default
        searchController.delegate = self
        searchController.searchBar.delegate = self
        searchController.searchResultsUpdater = self
        searchController.searchBar.autocapitalizationType = .words
        searchController.dimsBackgroundDuringPresentation = false
        searchController.hidesNavigationBarDuringPresentation = false
        searchController.searchBar.sizeToFit()

        tableView.tableHeaderView = searchController.searchBar
    }

请观看此视频,您可以看到此行为。 https://www.dropbox.com/s/l3m3q8wmqoy3qv2/SearchBarBug.mov?dl=0

我该如何解决?

1 个答案:

答案 0 :(得分:0)

我删除了UISearchController并使用了UISearchBar,这对我有用。

 fileprivate func addSearchController() {
        searchBar.barStyle = .default
        searchBar.delegate = self
        searchBar.autocapitalizationType = .words
        searchBar.showsCancelButton = true
        searchBar.sizeToFit()

        tableView.tableHeaderView = searchBar
    }