[英]hide custom search bar on start
in my swift 2 app i have a table view controller where i added a custom search bar (dark grey row) 在我的Swift 2应用程序中,我有一个表格视图控制器,在其中添加了一个自定义搜索栏(深灰色行)
in the viewDidLoad i call 在viewDidLoad我打电话
configureCustomSearchController()
this is the function: 这是功能:
func configureCustomSearchController() {
customSearchController = CustomSearchController(
searchResultsController: self,
searchBarFrame: CGRectMake(0.0, 0.0, MyTable.frame.size.width, 50.0),
MyTable.tableHeaderView = customSearchController.customSearchBar
customSearchController.searchBar.sizeToFit()
customSearchController.customDelegate = self
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
// DO SOMETHING
}
func didStartSearching() {
// DO SOMETHING
}
func didTapOnSearchButton() {
// DO SOMETHING
}
func didTapOnCancelButton() {
// DO SOMETHING
}
func didChangeSearchText(searchText: String) {
// DO SOMETHING
}
My Question is, how can i hide the searcher, if my tableview will appear and show the sidebar if i pull down. 我的问题是,如果我将出现tableview,并且如果我下拉菜单,将显示边栏,如何隐藏搜索器。
a pull down refresh function is available. 下拉刷新功能可用。
i found my solution: 我找到了解决方案:
viewDidLoad viewDidLoad
MYTable.contentInset = UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0)
this hide the searchbar on start and if i scroll a little bit up, the search Bar will be visible 这会在开始时隐藏搜索栏,如果我向上滚动一点,搜索栏将可见
if you want to show searchbar when user scroll down then add this Code 如果要在用户向下滚动时显示搜索栏,请添加此代码
self.MyTable.tableHeaderView = customSearchController
self.MyTable.contentOffset = CGPointMake(0, CGRectGetHeight(customSearchController.frame))
customSearchController.delegate = self
If you want to hide the header which contains your custom search bar you can try the following solutions: 如果要隐藏包含自定义搜索栏的标题,则可以尝试以下解决方案:
When you have to hide header (At start): 当您必须隐藏标题时(开始时):
tableview.contentOffset = CGPointMake(0,44)
When you have to show header (On the pull down action ): 当您必须显示标题时(在下拉动作上):
tableview.contentOffset = CGPointMake(0,0)
Ref: https://stackoverflow.com/a/14433304/4557505 参考: https : //stackoverflow.com/a/14433304/4557505
Another option is 另一种选择是
table.tableHeaderView = nil
And later if you want to show it then just assign it again, 然后,如果您想显示它,然后再次分配它,
table.tableHeaderView = theHeaderView;
You can find more information about this on https://stackoverflow.com/a/8079933/4557505 您可以在https://stackoverflow.com/a/8079933/4557505上找到有关此信息的更多信息
Hope this may help you 希望这对您有帮助
Else you may set your search bar on the viewController's view and show/hide that based on your pull to refresh 否则,您可以在viewController的视图上设置搜索栏,并根据您的拉动来显示/隐藏该刷新条
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.