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
Related
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.
I am running into a small problem, I implemented the new iOS 11's style search bar in my app, and I noticed that it disappeared with a slightly different animation from the one in Messages for example. It's faster and less smooth.
Anyone has ever stumble upon this "problem" ?
Here is the code I use :
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.barTintColor = .white
searchController.searchBar.layer.borderColor = UIColor.white.cgColor
searchController.searchBar.layer.borderWidth = 1
}
definesPresentationContext = true
searchController.searchBar.placeholder = "all_search".localized
EDIT:
I don't know if it will help you, but I am scrolling at a normal pace .
Thanks
Adding
self.extendedLayoutIncludesOpaqueBars = true
to my viewDidLoad solved the issue, your navigation bar must not be translucent and note that extendedLayoutIncludesOpaqueBars = true is being attributed to my main view which holds the tableview.
This happens when your table view doesn't go all the way to the top of the view. Make sure your table view is "behind" the navigation bar and uses extended edges and extend under opaque edges if your navigation bar is opaque.
Try this, it fixes it for me. I used a different UIViewController as the searchResultsUpdater and just set extendedLayoutIncludesOpaqueBars as true.
searchResultsUpdater.extendedLayoutIncludesOpaqueBars = true
searchController.searchResultsUpdater = searchResultsUpdater
UIView.animate(withDuration: 1, animations: {
//your codes to implement
}, completion: nil)
change withDuration: in seconds
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
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
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.