从详细信息视图返回后单击取消时

从详细信息视图返回后单击取消时

本文介绍了iOS,Swift 3 - 从详细信息视图返回后单击取消时,UISearchBar 消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 containerView 中有一个 tableView.以编程方式向其中添加了一个 searchBar.一切正常,除了以下情况:当我点击一个单元格时,tableView 被 searchBar 过滤,然后我从 detailView(通过 push segue 呈现)返回,然后我关闭 searchBar(取消按钮),然后搜索栏消失.奇怪的是,当我在控制台上调试它时,searchBar 对象仍然存在并且它仍然是 tableView 的 headerView ...任何人都有想法,可能导致此问题的原因以及如何解决?

I have a tableView in a containerView. Programmatically added a searchBar to it. Everything works fine, except for the case: When I tap on a cell, while the tableView is filtered by the searchBar, and then I return from the detailView (that was presented via push segue) and then I dismiss the searchBar (cancel button), then the searchBar disappears.Mysteriously, when I debug it on the console, the searchBar object is still there and it is still the headerView of the tableView...Anybody has an idea, what could cause this problem, and how to fix it?

这是我的相关代码:

在 viewDidLoad 中:

In viewDidLoad:

self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.definesPresentationContext = false
self.tableView.tableHeaderView = self.searchController.searchBar

searchControllerDelegate:

searchControllerDelegate:

func willPresentSearchController(_ searchController: UISearchController) {
    if let mpvc = self.parent as? MyPulleyViewController {
        mpvc.navigationController?.navigationBar.isTranslucent = true
    }
}


func willDismissSearchController(_ searchController: UISearchController) {
    if let mpvc = self.parent as? MyPulleyViewController {
        mpvc.navigationController?.navigationBar.isTranslucent = false
    }
}

(myPulleyViewController是包含containerView的VC,self是containerView的VC)

(myPulleyViewController is the VC containing the containerView, self is the containerView's VC)

在 IB 上,mpvc 设置为扩展边:在不透明条下

On the IB, the mpvc is set to Extend edges: Under Opaque Bars

感谢您的帮助!

推荐答案

我遇到了同样的问题,我认为这是 iOS 的问题,我通过为搜索结果制作视图控制器来修复它:

I faced the same problem, I think this is iOS issue, I fixed it by making viewcontroller for Search Result :

   let searchVC = mainStoryboard.instantiateViewController(withIdentifier: identifier) as! SearchResultViewController
    let searchController = UISearchController(searchResultsController: searchVC)
    searchController.searchResultsUpdater = searchVC

它工作正常.

这篇关于iOS,Swift 3 - 从详细信息视图返回后单击取消时,UISearchBar 消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 14:37