Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UISearchController中更改暗显的背景_Ios_Swift - Fatal编程技术网

Ios 在UISearchController中更改暗显的背景

Ios 在UISearchController中更改暗显的背景,ios,swift,Ios,Swift,我有一个表视图,它使用NSFetchedResultsController从存储有核心数据的数据库加载数据。我实现了一个UISearchController,我希望它在选中搜索栏且搜索栏为空时使背景变暗,并在出现某些文本时显示可滚动的结果 我试图在演示过程中更改UISearchController的DIMSBackground属性,直到我仅在视图将出现的功能中更改此值为止。但当我试图根据搜索栏文本的状态更改属性时,背景始终保持暗显 这是我的updateSearchResultsForSearch

我有一个表视图,它使用
NSFetchedResultsController
从存储有核心数据的数据库加载数据。我实现了一个
UISearchController
,我希望它在选中搜索栏且搜索栏为空时使背景变暗,并在出现某些文本时显示可滚动的结果

我试图在演示过程中更改
UISearchController
DIMSBackground属性,直到我仅在
视图将出现的功能中更改此值为止。但当我试图根据搜索栏文本的状态更改属性时,背景始终保持暗显

这是我的
updateSearchResultsForSearchController
函数:

func updateSearchResultsForSearchController(searchController: UISearchController) {
    if let searchText = self.searchController.searchBar.text {
        var scope: String = ""
        let scopeButton = searchController.searchBar.selectedScopeButtonIndex
        switch scopeButton {
        case 0:
            scope = "cardName"
        case 1:
            scope = "minionType.type"
        case 2:
            scope = "tagAbility.ability"
        default:
            scope = ""
        }

        let searchPredicate = NSPredicate(format: scope + " contains[c] %@", searchText)
        filteredCards = self.fetchedResultsController.fetchedObjects?.filter() {
            return searchPredicate.evaluateWithObject($0)
            } as? [Card]

        filteredSections = evaluateSectionsAfterSearch(filteredCards)

        if searchText.isEmpty {
            self.searchController.dimsBackgroundDuringPresentation = true
            self.searchControl = false
        } else {
            self.searchController.dimsBackgroundDuringPresentation = false
            self.searchControl = true
        }
        print(self.searchController.dimsBackgroundDuringPresentation)

        self.tableView.reloadData()
    }
}
searchControl变量用于确定在调用
reloadData
函数时,表视图必须加载哪个数组。
我找不出背景为什么保持暗显,使用
打印
命令显示该值设置正确。

不幸的是,
DIMSBackground在演示过程中
仅影响下一个演示,在演示searchController时无法打开/关闭它