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时无法打开/关闭它