Ios UISearchController隐藏搜索栏

Ios UISearchController隐藏搜索栏,ios,objective-c,uisearchbar,Ios,Objective C,Uisearchbar,我的UITableViewController中有一个UISearchController。我想隐藏搜索栏,直到用户向下滚动。在旧的UISearchDisplayController中,我的viewDidLoad方法中有以下代码: //Hides the search bar until user manually scrolls up. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection

我的UITableViewController中有一个UISearchController。我想隐藏搜索栏,直到用户向下滚动。在旧的UISearchDisplayController中,我的viewDidLoad方法中有以下代码:

//Hides the search bar until user manually scrolls up.
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
CGRect newBounds = self.tableView.bounds;
newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
self.tableView.bounds = newBounds;

不幸的是,上面的代码不再适用于UISearchController。

刚刚解决了问题。下面的说法是错误的

newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
应该是

newBounds.origin.y = newBounds.origin.y + self.searchController.searchBar.bounds.size.height;

而不是self.searchBar,它需要是self.searchController.searchBar

刚刚解决了这个问题。下面的说法是错误的

newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
应该是

newBounds.origin.y = newBounds.origin.y + self.searchController.searchBar.bounds.size.height;
它需要是self.searchController.searchBar,而不是self.searchBar