2016-09-27 98 views
2

我有一個簡單的tableViewController,一個searchBar與範圍和navigationBarSearchBar和NavigationBar之間的空白 - Swift

當我點擊我的searchBar我看到我的範圍和所有作品。然後,我點擊一行,我去我的DetailPage和搜索欄不隱藏(我不知道爲什麼)。

所以我點擊取消然後我回到我的tableView。當我返回到我的tableView時,我的SearchBar和我的NavigationBar之間有一個空格。

Blank space

這是我的代碼:

 self.resultSearchController = ({ 
      let controller = UISearchController(searchResultsController: nil) 
      controller.searchResultsUpdater = self 
      controller.hidesNavigationBarDuringPresentation = true 
      controller.dimsBackgroundDuringPresentation = false 
      controller.searchBar.sizeToFit() 
      controller.searchBar.scopeButtonTitles = ["Title", "Author", "Location", "Price", "User"] 
      self.tableView.tableHeaderView = controller.searchBar 
      return controller 
     })() 

func updateSearchResults(for searchController: UISearchController) 
    { 
     let scopes = resultSearchController.searchBar.scopeButtonTitles 
     let currentScope = scopes![resultSearchController.searchBar.selectedScopeButtonIndex] as String 
     filterContentForSearchText(searchText: searchController.searchBar.text!, scope: currentScope) 
    } 
+0

我認爲調整ScrollView Insets爲false適用於您...您的控制器屬性檢查器取消選中調整ScrollView插入 –

+0

我已經嘗試過但結果相同 – Carlo

+0

您是否通過記錄'frames'來確定邊界的實體帳戶? ? (_header,insets,searchbar_)將'viewDidLoad'中的代碼與'viewWill/DidAppear'區分開來的是什麼? – Aerows

回答

3

嘗試添加

self.automaticallyAdjustsScrollViewInsets = false; 

    self.extendedLayoutIncludesOpaqueBars = true 

viewDidload

+0

無。錯誤是一樣的。每次在使用搜索欄和範圍之後轉到我的詳細信息頁面時,在導航欄和表格視圖 – Carlo

+0

之間添加一個空白區域,在您的主視圖中添加一個空標籤(在搜索欄上方添加一個空標籤 - 即您的標籤應該是第一個控件在你的視圖層次結構中) – Lion

+0

我已經解決了謝謝 – Carlo