我将searchBar放在UITableView的第一个单元格中(不在UITableView标头中!):
firstCell.contentView.addSubview(searchController.searchBar)
当搜索发生时,我取消了隐藏导航栏:
searchController.hidesNavigationBarDuringPresentation = false
和下面的完整设置searchController代码:
func setupSearchController(){
//custom Search Results Controller
let folderSearchVC = FolderSearchViewController()
searchController = UISearchController(searchResultsController: folderSearchVC)
//cancel hide NavigationBar
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchResultsUpdater = folderSearchVC
searchBar = searchController.searchBar
searchBar.placeholder = "搜索习惯组"
firstCell.contentView.addSubview(searchBar)
}
但是,当我第一次激活searchBar时,占位符文本只会第一次向上跳一点(GIF下的演示):
您可以在演示gif文件中看到,当我第一次点击searchBar时,占位符文本会略微向上跳跃,然后跟随点击就可以了!
我的问题是如何禁止占位符文本向上跳??? 谢谢;)