How to hide UISearchController inside of navigation bar - ios

I want to dismiss/hide UISearchController from navigation bar when I switch tabs, I tried many things, if I set it to nil a black layer is shown in the search space. The settings view controller should not present the UISearch any thoughts?

Without seeing your code, this is what I would do if I wanted to hide my search bar. Use the following code to hide searchBar:
searchBar.isHidden = true
view.backgroundColor = .orange
//.clear? Or whatever colour you want to be there in the background.
//In viewDidLoad put
searchBar.isHidden = false

I was adding only one Navigation Controller to all tabs, I changed it, now for each tab I have an independent navigation controller, so it is solved.

Related

SearchController changes the size of tableView

The size of my tableView mysteriously changes heights when the search controller is active like the images I attached below.
The image in the far left is the initial state. Middle image is when the search controller is active and the last image is when the search controller is dismissed.
I tried setting the content size of the tableview when the search controller is active, in the viewDidLoad, viewWillAppear and viewDidAppear without any luck.
Any idea on how to resolve this problem?
P.S. The items you see are just dummy posts.
Try set edgesForExtendedLayout property to be under Top Bar using code
or storyboard
I solved it by setting the extendedLayOut to 0
self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)
However, the status bar was covering the search bar so I hide the status bar when the searchController is active
override var prefersStatusBarHidden: Bool {
return searchController.isActive
}

Hide bar button items swift

How can I hide my left bar button item?
In my storyboard I dragged a Navigation Bar onto my View Controller, then a Bar Button Item. Under certain conditions I want to hide the Bar Button Item.
None of this works:
override func viewDidLoad() {
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.leftBarButtonItems = []
self.navigationItem.setLeftBarButtonItems([], animated: true)
}
I dragged a Navigation Bar onto my View Controller
Well, don't! There is a big difference between a navigation controller interface, where you set the navigationItem, and a loosey-goosey navigation bar just sitting there in the interface, which is what you have.
Embed your view controller in a UINavigationController and do things the right way. Then setting your navigationItem and its properties will work as expected.
You can't access to self.navigationItem.leftBarButtonItem because you manually drag navigationBar from storyboard. I would suggest to do the following instead:
add an IBOutlet of BarButtonItem (eg: barButton) that you created in storyboard
barButton.title = ""
barButton.isEnable = false
This will hide your BarButtonItem, and you can simply show it back later.

Completely disable the Navigation Controller

I have used the 'Embed In' navigation controller within the storyboard. Is there a way to completely disable the whole navigation bar? I have tried the code below, but when there is a swipe, the navigation bar appears again. I want to be able to completely hide the whole bar until a condition is met. Is there a way to do this?
self.navigationController?.hidesBarsOnSwipe = true
self.navigationController?.hidesBarsOnTap = true
I have tried a custom navigation bar, but I couldn't get a nice scroll effect like with the default navigation bar.
To hide the navigationBar just do:
self.navigationController?.navigationBar.isHidden = true
Add this row in your viewDidLoad.
You can use this in viewDidLoad:
self.navigationController?.setNavigationBarHidden(true, animated: false)

Navigation controller's toolbar not being hidden after enabling hide on tap?

I have a navigation controller where I have enabled hide on tap.It hides at first when I tap on the screen but when I tap again,the nav bar hides but the toolbar does not hide at all and it is obstructing my view. I have already tried settoolbarhidden and toolbar.hidden properties but it does not work.How do I solve this?
EDIT : I need to hide it only on this screen,I need the toolbar for other screens so thats why I have enabled shows toolbar.
EDIT 2 : Let me frame my question better.
When I enter the view controller :
Both navbar and toolbar hides because I have set it to hidden which is good
When I tap the screen :
Both navbar and toolbar shows because I have set it this way in the previous view controller.(If possible,Can I only show/hide the navigationbar on tap not the toolbar?
And lastly when I tap it again to hide both bars :
The navigation bar hides but the toolbar does not go away? This is my problem.
As Per your question you want to show tool bar on a particular viewController. View Controller viewWillAppear Function Hide ToolBar and viewDidDisappear show your tool bar it will show on other view controllers.
" Please check the navigation controller checkbox its disable or not.After that set this on your view controller before your profile view controller "
override func viewWillAppear(animated: Bool) {
self.navigationController?.toolbarHidden = true;
}
override func viewDidDisappear(animated: Bool) {
self.navigationController?.toolbarHidden = false;
}
I think it will resolve your issue.
I had the same problem.
The hideBarsOnTap only work if you placed smth in it. So if it is empty it will stay.
You could just put a blank imageView or Label there for example.
Or if you want it completely blank, your only option is to put a tabGestureRecognizer on your View!

Search bar bug - iOS

In my app I have this kind of bug:
When I scroll down, the content of table is seen above the search bar. What can be the reason?
override func viewDidLoad() {
super.viewDidLoad()
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.barTintColor = UIColor(red: 52.0/255.0, green: 73.0/255.0, blue: 94.0/255.0, alpha: 1.0)
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
self.tableView.reloadData()
}
The iOS Human Interface Guidelines list 3 methods to prevent content from showing through the status bar.
Use a navigation controller to display content. A navigation controller automatically displays a status bar background and it
ensures that its content views don’t appear behind the status bar. (To
learn more about navigation controllers, see Navigation Controllers.)
Create a nondistracting custom image—such as a gradient—and display it behind the status bar. To ensure that the image stays
behind the status bar, you could use a view controller to keep the
image above a scrolling view or you could use a scrolling view to keep
it pinned to the top.
Position content to avoid the status bar area (that is, the area defined by the app’s statusBarFrame property). If you do this, you
should use the window’s background color to provide a solid color
behind the status bar.
You should make the status bar not translucent.
The status bar's color is a property of UIApplication. You need to set it to a valid UIStatusBarStyle.
The new UISearchController has been designed to work with a UITableView and a UINavigationBar. Its functionality depends on your navigation bar being present. when the search bar has content in its text field, it will be latched on top of the page under the navigation bar. well, you don't have any navigation bar, it will latch to the top view guide and it always takes into account the status bar (if present) I guess the only way you can resolve your problem without an actual navigation bar is to add a view under status bar and make it opaque just like your search bar. it's a bit hacky but it's alright in my book.

Resources