2

I have a simple tableViewController, a searchBar with scopes and a navigationBar.

When I click on my searchBar I see my scopes and all works. Then I click on a row and I go to my DetailPage and the search bar isn't hidden (I don't know why).

So I click cancel and then I return to my tableView. When I return to my tableView there is a blank space between my SearchBar and my NavigationBar.

Blank space

This is my code:

      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)
    }
Carlo
  • 813
  • 1
  • 15
  • 34
  • I think adjust ScrollView Insets to false works for you ... your controller attribute inspector uncheck adjust ScrollView Insets – Bhavin Bhadani Sep 27 '16 at 07:48
  • I have tried but the result is the same – Carlo Sep 27 '16 at 07:56
  • Have you identified what entity accounts for the margin by logging the `frames`? (_header, insets, searchbar_) What separates your code in `viewDidLoad` from `viewWill/DidAppear`? – Aerows Sep 27 '16 at 08:02
  • My resultSearchController is in my viewDidLoad method. I don't have viewWill/DidAppear method. The search bar is the problem because when I click that it become bigger because of my scopes. – Carlo Sep 27 '16 at 08:08
  • set SearchBar position : ( 0 , 24,Width ,Height) – Shobhakar Tiwari Sep 27 '16 at 08:12
  • search bar position doesn't work – Carlo Sep 27 '16 at 08:20

1 Answers1

8

try to Add

  self.automaticallyAdjustsScrollViewInsets = false;

  self.extendedLayoutIncludesOpaqueBars = true

in viewDidload.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Nothing. The error is the same. Each time I go to my detail page after using search bar with scopes a blank space is added between navigation bar and table view – Carlo Sep 27 '16 at 08:17
  • once try by adding one empty label in your main view (above your search bar - i.e. your label should be first control in your view hierarchy) – Ketan Parmar Sep 27 '16 at 08:22