首页 > 解决方案 > 如何使用搜索栏过滤器解决错误,然后快速展开 segue?

问题描述

我目前在 mainPage( viewController) - tableView in viewController> searchbarPage( ) -> subPage( viewController) 顺序中有一个屏幕。

subPage 有一个back button并使用unwind segue. 然后按back button返回主页面。

在 searchbarPage 中,选择tableViewcell不应用过滤器,将其移动到子页面,按返回按钮,unwind segue 将正常工作。

但是,当我使用过滤器转到子页面searchbar并按后退按钮时,会发生错误。

我不知道为什么会这样。

// Unwind Segue - mainPage
    @IBAction func gotoMainPage(_ sender: UIStoryboardSegue){
    }

// Search Bar filter - search Page
    func updateSearchResults(for searchController: UISearchController) {
        if searchController.searchBar.text! == "" {
            self.filterSearch = self.MainDAO.find() // sqlite select
        } else {
            self.filterSearch = self.MainDAO.find().filter( {$0.itemName.lowercased().contains(searchController.searchBar.text!.lowercased()) }) 
        }
        self.tableView.reloadData()
    }

标签: iosswift

解决方案


尝试使用此代码,它将帮助您它对我有用

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
            searchController?.isActive = false // Add this !
            dismiss(animated: true)
}

推荐阅读