Show UISearchController while scrolling the View table

I implemented the search bar in my test application through the UISearchController. when I launch my application, I see a search bar under the navigation controller. but how can I hide it when the application starts, and show it only when I pull the table down? and hide again when you pull up the table? I can not find a solution on google or youtube, please help.

EDIT: this is how I implement the UISearchController inviewDidLoad

//set the searchController
searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.sizeToFit()
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search your restaurant"
tableView.tableHeaderView = searchController.searchBar
definesPresentationContext = true

tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
+4
source share
2 answers

Put the following segment in yours viewDidLoad, so you ask to UITableViewscroll and hide SearchBarat the beginning:

tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)

TableViewHeader searchController:

tableView.tableHeaderView = searchController.searchBar

:

, :

tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)

:

self.tableView.contentOffset = CGPointMake(0.0, 44.0)

!

+7

Swift 3:

viewController 0, 0 .

, HeaderView , 0.

.

override func viewDidAppear(_ animated: Bool) {

    self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: false)

}
+1

Source: https://habr.com/ru/post/1610091/


All Articles