Can I insert a button in a UISearchDisplayController?

When the user clicked in the search bar, did not enter any text, and the screen went dark (but the table view has not yet appeared), I would like to place a button on the screen to allow the user to switch to other functions. Is it possible?

Thanks!

+4
source share
1 answer

This is pretty tricky. _dimmingView is private to searchDisplayController, and it goes above all subzones. What you can do is cover it with your custom view every time it appears ([searchString length] == 0 and DidBeginSearch)

(tempView frame set for UISearchBar placed in tableViewHeader)

- (void)viewDidLoad { tempView = [[UIView alloc] initWith...]; // tempView setup ... } - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller { [tempView setFrame:CGRectMake(0, self.searchDisplayController.searchBar.frame.size.height, 320, self.searchDisplayController.searchResultsTableView.frame.size.height)]; [self.searchDisplayController.searchContentsController.view addSubview:tempView]; ... } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { if ([searchString length] == 0) [self.searchDisplayController.searchContentsController.view addSubview:tempView]; else [tempView removeFromSuperview]; ... } - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { if (tempView && tempView.superview) [tempView removeFromSuperview]; ... } 

Notes. I tried to create a new instance on DidBeginSearch and release it on DidEndSearch, and it worked only for the first call! Weird ...

Hope this helps

+2
source

Source: https://habr.com/ru/post/1347278/


All Articles