0

I am setting up searchController as below in viewDidLoad() in my view controllers. One VC has table view embedded and another is UITableViewController.

I am using another VC to allow user to select a value and use that to filter tables items using unwind segue.

self.searchController.obscuresBackgroundDuringPresentation = false
    self.searchController.hidesNavigationBarDuringPresentation = true

if #available(iOS 11.0, *)  {


    self.searchController.searchBar.delegate = self
    self.navigationItem.searchController = self.searchController
    self.navigationController?.navigationBar.prefersLargeTitles = true            
    self.searchController.searchBar.scopeButtonTitles = ["All", "<= 2", "<= 5", "<= 10"]

    self.navigationItem.hidesSearchBarWhenScrolling = true

}

i do the below in unwind method.

DispatchQueue.main.async {

                self.searchController.searchBar.text = searchText

                let scope = self.searchController.searchBar.scopeButtonTitles![self.searchController.searchBar.selectedScopeButtonIndex]

                self.filterContentForSearchText(searchText, scope: scope)

            }

When table with data is loaded, search bar is hidden completely under navigation bar but when i assign value to the searchtext field that doesnt yield any items from data source, the search field clear icon shows as below.

I am using DZNEmptyDataSet framework to handle empty views. Earlier i had configured search bar from IB and at that below issue didnt come. Was using DZNEmptyDataSet at that time also.

enter image description here

What could be the issue?

Xcode 9.3 Testing in 11.3 simulator and 8 Plus.

Thanks Ashish

ashishn
  • 410
  • 5
  • 18
  • Try setting `navigationItem.searchController = searchController` – Scriptable May 23 '18 at 14:36
  • but i am already doing that. – ashishn May 24 '18 at 07:04
  • oh I must of missed that. – Scriptable May 24 '18 at 07:36
  • Try this one for hide search bar : self.navigationController.navigationItem.searchController.active = false; – guru May 29 '18 at 05:40
  • No it didn't work but i was able to show the search controller in unwind method by calling searchController.isActive = true on main queue as mentioned in https://stackoverflow.com/questions/27951965/cannot-set-searchbar-as-firstresponder/37848770#37848770. Keeping the question open in case someone is able to suggest a solution. – ashishn Jun 01 '18 at 17:54

0 Answers0