DisplaySearchBarInNavigationBar deprecated in iOS8

I am trying to find an alternative to displaySearchBarInNavigationBar for iOs8, is there anything I can use (in quick)?

I tried self.navigationItem.titleView = resultSearchController.searchBar but did nothing.

I don’t understand how to find a replacement for functions that are deprecated in the documentation for the box that he just says is deprecated without an alternative, if you have any advice, it will be very useful.

+6
source share
1 answer

You can put the UISearchBar in the UINavigationBar without using the UINavigationController without any problems, but you only need to make minor changes, you first need to define the @IBOutlet for the UINavigationItem inside your UINavigationBar , but its name must be different from the navigationItem property defined in the whole UIViewController class, see the following code:

 class ViewController: UIViewController, UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate { var searchController : UISearchController! @IBOutlet weak var navigationItemBar: UINavigationItem! override func viewDidLoad() { super.viewDidLoad() self.searchController = UISearchController(searchResultsController: nil) self.searchController.searchResultsUpdater = self self.searchController.delegate = self self.searchController.searchBar.delegate = self self.searchController.hidesNavigationBarDuringPresentation = false self.searchController.dimsBackgroundDuringPresentation = true self.navigationItemBar.titleView = searchController.searchBar self.definesPresentationContext = true } func updateSearchResultsForSearchController(searchController: UISearchController) { } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 

And then you can see something like this in your simulator:

enter image description here

Hope this helps you.

+8
source

Source: https://habr.com/ru/post/988416/


All Articles