2016-03-26 85 views
0

我在我的UITableViewController中有一個UISearchController。我希望隱藏搜索欄,直到用戶向下滾動。在舊UISearchDisplayController,我在我的viewDidLoad方法如下代碼:UISearchController隱藏搜索欄

//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工作。

回答

2

剛剛發現了問題。以下是錯誤的,

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