有2個未回覆的帖子here和here,其中沒有人提供瞭解決此問題的工作方案。iOS 11在tableViewHeader中的搜索欄跳轉到焦點上的屏幕頂部
第一張圖顯示了搜索控制器的iOS 10行爲,您可以在其中看到左側的層次結構,右側的搜索控制器框架以紅色框起。在中心以藍色顯示的是在表格中正確顯示的。
第二個圖像顯示的iOS 11行爲,其中搜索控制器退出tableView
標題的邊界內,並移動到不具有意義的屏幕的頂部,因爲表視圖被從屏幕的頂部定位在230個像素。
我用於顯示所有的這種代碼是下面的(在viewDidLoad
):
self.definesPresentationContext = YES;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.clipsToBounds = YES;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.placeholder = @"Enter name or email";
[self.searchController.searchBar sizeToFit];
而他們完全放棄支持用於搜索欄的tableView標題部分?我發現它能夠像預期的那樣聚焦。任何有關此文檔的參考文獻都證明了這一說法? – Aleksandar
這並不是說標題視圖已從表格中刪除,但現在應該在導航項目中執行搜索。請參閱此WWDC對話[更新您的iOS 11應用程序](https://developer.apple.com/videos/play/wwdc2017/204/)幻燈片第23頁。 – zcui93
這是Apple推薦的內容,但並不總是有效:[iOS11 UISearchBar在嵌入UISplitViewController時在UINavigationBar中丟失](https://stackoverflow.com/questions/46387166/ios11-uisearchbar-missing-in-uinavigationbar-when-embedded-in-uisplitviewcontrol)。你仍然可以使用tableHeaderView,但不是沒有一些調整... [在iOS11的tableHeaderView中使用UISearchController與UISearchBar](https://stackoverflow.com/questions/46737117/using-uisearchcontroller-with-uisearchbar-in-tableheaderview-in -ios11) –