Search Bar disappear when typing - ios

I have a problem with my search bar. As I begin to type, my search bar disappears. I've tried many solutions that have been listed here but none of them worked. I've added the search bar right under my nav bar and on top of my custom collection view, however I did not add it to the header of my collection view nor did I add it to the nav bar. I also want to note that I've done most of my code programmatically.
Here are some of the methods that I have already tried:
func setupSearchController(){
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
self.definesPresentationContext = false
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = "Type Here..."
searchController.searchBar.sizeToFit()
// let text = searchController.searchBar.text
searchController.isActive = false
// searchController.searchBar.text = text
self.searchController.extendedLayoutIncludesOpaqueBars = true
searchController.searchBar.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
}
Before picture
After typing picture

Related

Search Bar disappears in scrolling, how to prevent this action

My search bar seems to disappear on scrolling, even if i were use
navigationController?.hidesBarsOnSwipe = false
Also using below
navigationItem.searchController = searchController
has no effect
Seems to have no effect, my code for search controller addition is
searchControlInstance = UISearchController(searchResultsController: nil)
searchControlInstance.searchResultsUpdater = self
searchControlInstance.obscuresBackgroundDuringPresentation = false
self.definesPresentationContext = true
searchControlInstance.searchBar.returnKeyType = .done
navigationItem.hidesSearchBarWhenScrolling = false
I do have
navigationController?.navigationBar.prefersLargeTitles = true
but turning it to false seems to have no effect the search bar just disappears like in picture, where am i making the mistake, can any one suggest, i do not use storyboard
You have to set it in this way:
navigationItem.searchController = searchControlInstance
navigationItem.hidesSearchBarWhenScrolling = false

What is this strange white space at the top of my UIViewController when using the Search Controller on my device?

Left side displays my app in the iPhone 7 simulator. Right side is the app as displayed in my device. When tapping in the search bar, the navbar sildes up but then slides back down as showing in the image with the "What is this?" text.
The code for my search controller is as follows and it is being called in viewDidLoad.
//MARK: - Search Controller
func configureSearchController() {
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
// to receive updates
searchController.searchResultsUpdater = self
// Set up searchbar of search controller
searchController.searchBar.scopeButtonTitles = ["All", "Something", "Something"]
searchController.searchBar.delegate = self
// add the searchbar to the tableview
tableView.tableHeaderView = searchController.searchBar
// hack to fix ocassional bugs
searchController.searchBar.sizeToFit()
}

Navigation bar Searchbar Space Is not Hiding in Swift 4.2

HI i have implemented Searchbar in Navigationbar and
Hiding Navigationbar Progamatically but the space is not removing
PLease help how can i remove the space of searchbar hiding space
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.obscuresBackgroundDuringPresentation = false
search.hidesNavigationBarDuringPresentation = false;
search.searchBar.placeholder = "search..."
self.definesPresentationContext = true
self.navigationItem.searchController = search
for Hiding the SearchBar
search.searchBar.isHidden = false
Hiding it won't be enough because it is still the navigationItem searchController, so you need to set it to nil
self.navigationItem.searchController = nil
and later restore it if you want, simple as that.

How to disable or hide the scope buttons in searchbar?

I am new to ios I am using Xcode 7 and swift 2 I have implemented a searchbar controler with my tableViewController like this:
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
definesPresentationContext = false
searchController.dimsBackgroundDuringPresentation = false
// Setup the Scope Bar
searchController.searchBar.scopeButtonTitles = ["All", "Chocolate"]
searchController.searchBar.showsScopeBar = false
searchController.searchBar.searchBarStyle = .Default
tableView.tableHeaderView = searchController.searchBar
But I don't want the scope buttons in this case. How can I hide them?
Note, this is not working for me:
searchController.searchBar.showsScopeBar = false
Storyboard
Using Search Display Controller via storyboard, go to the search bar attributes inspector and uncheck the "Shows Scope Bar" if it is checked.and remove the scope titles if any.
Programmatically
Using Search Display Controller programmatically then you have to remove this part, will not show the scope bar
searchController.searchBar.scopeButtonTitles = ["All", "Chocolate"]
searchController.searchBar.showsScopeBar = false
Or
Make the scopeButtonTitles to nil will also remove the buttons in scope bar
searchController.searchBar.scopeButtonTitles = nil

Why is UISearchController search bar incorrectly positioned?

I have a UITableViewController where I have placed a search bar in the tableHeaderView. It all looks fine like the picture below.
But, the problem is when it is presented:
As you can see, it is mostly hidden above the top of the screen.
Here is the code I used to set it up in the tableview controller's viewDidLoad:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Presets..."
searchController.searchBar.delegate = self
searchController.searchBar.barStyle = .blackTranslucent
searchController.hidesNavigationBarDuringPresentation = true;
self.tableView.tableHeaderView = searchController.searchBar
self.tableView.contentOffset = CGPoint(x:0, y:searchController.searchBar.frame.size.height);
If I print the frame of the searchbar, it's origin is (0,0).
I have tried everything I can think of, but nothing works
I figured out that if I check Translucent in the Navigation Bar's Attributes Inspector in IB the issue is resolved.
This leads me to believe that leaving that unchecked and setting extendedLayoutIncludesOpaqueBars to true would also work, but I found this not to be the case.

Resources