UISearchBar not showing on device but is showing in simulator - ios

I have a table view that I have added a search controller in to by putting the following in to my table views class which I made sure to add UISearchBarDelegate in the class definition.
let searchDisplay = UISearchController(searchResultsController: nil)
Then in my viewDidLoad function I entered this:
searchDisplay.searchResultsUpdater = self
searchDisplay.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchDisplay.searchBar
I then have functions that get the required data depending on what has been searched.
Also added this after the class but in the same file:
extension AllTableViewController: UISearchResultsUpdating{
func updateSearchResultsForSearchController(searchDisplay: UISearchController) {
filterContentForSearchText(searchDisplay.searchBar.text!)
}
}
As I say in the title the code all seems to run swimmingly in the Simulator but when I run it on a device the search bar just doesn't appear. No different messages appear in the output box so I don't really know where to start.

Have you tried a sizeToFit call on the search bar? – keithbhunter Jun 30 at 13:43

Related

Change UINavigationItem accessibility elements order

I have a UINavigationBar which contains 3 parts:
titleView (which is UISearchBar)
leftBarButtonItems
rightBarButtonItems
when the voice-over is on, the search bar will be the first one to be focused.
which is not confirmed to the left to right order we are familiar with.
I tried to set UINavigationItem's accessibilityElements, but it still will highlight the searchBar first. assume because, inside the UINavigationItem, the titleView is the first subView.
any ideas on how to change the order, thanks~
Any ideas on how to change the order?
I assume your problem deals with the way you added the search bar in the navigation bar.
I created a blank project as follows:
The code snippet hereafter is an example of adding a search bar as the title view: 🤓
class SearchViewController: UIViewController, UISearchBarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let search = UISearchBar()
search.showsCancelButton = true
search.delegate = self
self.navigationItem.titleView = search
}
}
The result with VoiceOver on gives rise to the following screenshots:
Following this rationale, you have the VoiceOver initial reading order from left to right in the navigation bar. 🥳🎊🎉
I suggest to take a look at this site if further information is needed about a11y in the navigation bar and especially if you want to make a specific reading order. 👍

Grey background in navigation bar with searchController added to navigationItem during push

I have a table view in navigation controller so that I can push the detail view controller on the stack. It works fine, until I add a search controller to the navigation item, like so:
searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.delegate = self
searchController.searchBar.tintColor = Colors.mlLabel
navigationItem.searchController = searchController
definesPresentationContext = true
It results in temporary grey background, see below:
When debugging the view hierarchy, it looks like UIViewControllerWrapperView's _UIParallaxDimmingView(selected below) is causing this, as both navigation bar and status bar are transparent.
How can I fix this?
Note: Setting the animated property in pushViewController() to false works, but I'd like to keep the animation.
Update: This seems to be issue only on iOS 13. Probably from some recent version even, as I didn't have this issue earlier.
Update 2: I've noticed the same issue on multiple places in my app now, and it's not just in combination with SearchController. Basically the _UIParallaxDimmingView sticks its nose out.
Update
Here's the code I use to go from a large title to a small title. These are properties for the large title viewcontroller, or more specific its navigation controller:
navigationController.navigationBar.prefersLargeTitles = true
navigationController.topViewController?.extendedLayoutIncludesOpaqueBars = true
Perhaps the second line above might help you?
As for pushing any view controllers, I see I've overridden the push-function from the navigation controller (as I use the navigation controller for each tab in my tabbar):
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count >= 1 {
viewController.hidesBottomBarWhenPushed = true
viewController.navigationItem.largeTitleDisplayMode = .never
}
super.pushViewController(viewController, animated: animated)
}
Previous answer
I saw this a couple of times before in my life and it always had to do something with the background color of the view controller itself. If it's transparent you see this stuff when animating.
But since it's a search controller, it might be the navigation bar. Anyway, since the issue is only since iOS13, I believe the issue can be resolved using this:
searchController.searchBar.backgroundColor = UIColor.clear (or whatever color)
This new property (UISearchBar.searchTextField.backgroundColor) has been added since iOS13, so maybe this will solve it for you? :)
I've finally found a solution. One of the problems was that I've set a background color for the navbar like so:
UINavigationBar.appearance().backgroundColor = .white
So removing the above line and adding the below line to the view controller being pushed fixed it.
extendedLayoutIncludesOpaqueBars = true

How Make SearchBar Like Iphone Setting

Hi Thanks For answers in advance I Have 2 Question First How to make search bar present like setting when nothing is searched yet the background shows the setting and second how is it from static tableview show the search result
searchController = UISearchController(searchResultsController: nil)
searchController?.searchBar.delegate = self
searchController?.dimsBackgroundDuringPresentation = true
searchController?.searchResultsUpdater = self
navigationItem.searchController = searchController
If I understood your question correctly, you have an empty UITableView, and you want to have a search bar when no search has been performed yet. Then, you want to have the search results appear in that table view.
First, I would suggest always having the search bar on top of the table view so that users can perform another search after the first one. But if that is not your goal, you could have the following:
var didPerformSearch: Bool = false
then, when the user performs the first search, set it to true. Then have :
if didPerformSearch == true {
yourSearchBar.isHidden = true
}else{
yourSearchBar.isHidden = false
}
Also, your results table view HAS to be dynamic, because the number of search results and the search results themselves will differ depending on the search.
So, use a dynamic table view and a UITableViewDelegate and UITableviewDataSource or a UITableViewController to show your search results, which I can't show you how to do because I don't know how you get your search results.
Hope I helped!
EDIT :
Okay so after reading your comments I actually understand what you want to do.
You could have a table view for search results on top of your ViewController with resultsTableView.isHidden = true.
Then, when the user taps the search bar, you would set resultsTableView.isHidden = false
OR
You could even animate it like this :
UIView.animate(duration: 0.2) {
resultsTableView.alpha = 1
}
(set it to 1 to show it, to 0 to hide it)

How can I remove the "<More" back header in my MoreController in a UITabView series of tabs

The issue that I'm running into is that I have a container view pegged to the top of each of my view controllers. When I go to the "more" section on a UITTabBar view then it has a "More" header on each of the sections. I'm hoping to get rid of that since the bar is now "over" my container since it is constrained to the superview. It also takes up too much real estate to have the "more" and my container view one after the other. Looking just to get rid of the more view controller header.
self.navigationItem.leftBarButtonItem = nil
So I was able to dig around and find and answer....
I created a class of UITabBarController and then added it to project
class newTabcont : UITabBarController{
func initializeTabs(){
customizableViewControllers = nil
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = true
self.moreNavigationController.navigationBar.hidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
initializeTabs()
}
}
and I no longer have an issue....

UISearchController in-accessible

I have implemented a search screen using UISearchController and a table view. When I start searching for something, the search controller adds a view on top of the table view (although, it does nothing) and until I set the searchController.active = false, the table view is in-accessible with VoiceOver. I have tried almost everything it seems, and the only solution is to abandon UISearchController for UISearchBar. Currently, once the keyboard is shown and the search controller is active, the VoiceOver selector will go from the text field, to a bar button item, then it skips the table view and goes to the keyboard. Here is my setup of UISearchController.
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.searchBarStyle = .Minimal
searchController.searchBar.keyboardAppearance = .Dark
searchController.searchBar.showsCancelButton = false
searchController.searchBar.delegate = self
searchController.searchBar.text = prefilledSearch
searchController.view.layer.borderColor = UIColor.redColor().CGColor
searchController.view.layer.borderWidth = 1.0
searchController.view.isAccessibilityElement = false
searchController.view.hidden = true
searchController.searchBar.setShowsCancelButton(false, animated: false)
How can I get this fixed and continue to use UISearchController? currently, search is not usable with VoiceOver users in my app.
That's because underlying UITransitionView sets incorrect value for accessibilityViewIsModalSelector which traps VO within search view, which in your case is empty.
I can only think of patching this behavior by swizzling accessibilityViewIsModal on private UITransitionView.
I described the technique in a blog post I wrote:
http://www.morphineapps.com/blog/accessibility-on-ios
Relevant gists:
https://gist.github.com/pronebird/0d3c06485de50e100d1e93bcde08c94c#file-snippet-m
https://gist.github.com/pronebird/66aa70b005ed9af8d357cdc7e940542b#file-search-controller-snippet-m
I've found that the accepted answer is suboptimal, even though it might be technically correct.
If you use the obscuresBackgroundDuringPresentation (added in iOS 9.1) and set it to false, VoiceOver can access the underlying table view.
Usage:
searchController.obscuresBackgroundDuringPresentation = false
From what I've found on this page, http://www.iaccessibility.net/report/uisearching-for-accessibility-nil, the problem is that you set searchResultsController to nil which makes the original view controller display the search results. When the search controller has focus it blocks VoiceOver from accessing the search results in the original view controller. By specifying a separate results view controller, VoiceOver will work.

Resources