【发布时间】:2016-09-27 07:46:09
【问题描述】:
我有一个简单的tableViewController、一个带作用域的searchBar 和一个navigationBar。
当我点击我的searchBar 时,我会看到我的范围和所有工作。然后我单击一行并转到我的DetailPage 并且搜索栏没有隐藏(我不知道为什么)。
所以我点击取消,然后我返回到我的tableView。当我返回到我的 tableView 时,我的SearchBar 和我的NavigationBar 之间有一个空格。
这是我的代码:
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.hidesNavigationBarDuringPresentation = true
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.scopeButtonTitles = ["Title", "Author", "Location", "Price", "User"]
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
func updateSearchResults(for searchController: UISearchController)
{
let scopes = resultSearchController.searchBar.scopeButtonTitles
let currentScope = scopes![resultSearchController.searchBar.selectedScopeButtonIndex] as String
filterContentForSearchText(searchText: searchController.searchBar.text!, scope: currentScope)
}
【问题讨论】:
-
我认为将 ScrollView Insets 调整为 false 对您有用...您的控制器属性检查器取消选中调整 ScrollView Insets
-
我试过了,结果是一样的
-
您是否通过登录
frames确定了哪些实体占保证金? (header、insets、searchbar)viewDidLoad和viewWill/DidAppear中的代码有什么区别? -
我的 resultSearchController 在我的 viewDidLoad 方法中。我没有 viewWill/DidAppear 方法。搜索栏是问题所在,因为当我点击它时,它会因为我的范围而变大。
-
设置 SearchBar 位置:( 0 , 24,Width ,Height)
标签: ios swift uitableview uisearchbar uisearchcontroller