UISearchController with nil searchResultsController
Asked Answered
R

4

6

I am using UISearchController with UITableView, and using same table view on my base view controller to display the search results (doing with not specifying a seperate search results controller as searchController = UISearchController(searchResultsController: nil) ).

However, despite setting searchResultsController as nil, an empty transparent _UISearchControllerView is still being presenting on top of my view controller when search is active.

Is there a way to prevent this and keep my view controller on the top of the view controller hiearchy on search?

Thanks.

Roadster answered 18/6, 2016 at 13:51 Comment(2)
Did you ever find a solution to this? I'm experiencing the exact same issue, and have no idea what to do.Lollard
@Lollard No, I couldn't find a solution at that times.Roadster
A
2

You can remove that by setting the dimsBackgroundDuringPresentation property of search controller to false

searchController.dimsBackgroundDuringPresentation = false
Auschwitz answered 19/6, 2016 at 8:44 Comment(1)
It's just a visual property as i know, doesn't work as I want to. Did you try it and see in view debugger, maybe i am missing something?Roadster
P
0

By default, UISearchController will dim the view it is presented over. This is useful if you are using another view controller for searchResultsController. In your code, you have set the current view to show the results, so you do not want to dim your view.

searchController.dimsBackgroundDuringPresentation = false
Phillane answered 30/6, 2016 at 9:1 Comment(0)
D
0

As of iOS 13, UISearchController#dimsBackgroundDuringPresentation is deprecated.

The correct way to prevent the containing view controller from being obscured is to use obscuresBackgroundDuringPresentation instead:

searchController.dimsBackgroundDuringPresentation = false

See the documentation:

When the value of this property is true, the search controller obscures the view controller containing your searchable content as soon as the user interacts with the search bar. When this property is false, the search controller does not obscure the original view controller. This property controls only whether the original view controller is initially obscured. When the user enters text in the search bar, the search controller immediately displays the search results controller with the results.

If you use the same view controller to display the searchable content and search results, it is recommended that you set this property to false. The default value of this property is true.

Dyewood answered 22/4, 2020 at 17:30 Comment(0)
R
-1

Hello folk please try this.

-(void) searchBar: (UISearchBar *) searchBar textDidChange:(NSString *)     searchText{
NSMutableArray *sortedData = [[NSMutableArray alloc] init];

    if ([searchText isEqualToString:@""]) {
        _localArray = _mainArray; // you must take a local array
    }
    else{
       //show your sorted data
    }

}

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
searchBar.text = nil;
[searchBar resignFirstResponder];
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[self.view endEditing:YES];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[self.view endEditing:YES];
}
Reynaldoreynard answered 24/6, 2016 at 5:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.