且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当 tableView 向下滑动时显示 UISearchController

更新时间:2023-11-05 23:33:52

将以下部分放在您的 viewDidLoad 中,所以发生的事情是您要求 UITableView 滚动并隐藏开头的 SearchBar :

Place the following segment in your viewDidLoad, so whats happening is your asking the UITableView to scroll and hide the SearchBar at the beginning :

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

并且不要忘记将 TableViewHeader 设置为您的 searchController :

And don't forget to set the TableViewHeader to your searchController :

tableView.tableHeaderView = searchController.searchBar

更新:

因为你有一个空的tableview,所以替换以下内容:

Because you have an empty tableview then replace the following :

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

与:

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

祝你好运!