In my app I have a UIViewController
that lets users search in a server database. (It's not filtering an existing list.) Results are displayed in a UITableView
, which is the searchResultsController
of the custom UISearchController
.
We need a different behaviour of the 'Cancel' button so we created subclasses of UISearchController and UISearchBar.
My issue is: VoiceOver doesn't see the UITableView
that display results. Instead of selecting the header, then the first row and so on, it selects the whole area and reads something about closing the view. (There's no 'Close' button). It seems like the UITableView
showing the results is hidden. Here's the view hierarchy when the searchResultsController
is presented.
If I initiate the searchController
with the default class, I get the correct behaviour (for VoiceOver, not for the 'Cancel' button).
The documentation doesn't say anything specific about subclassing.
Any hint?
Here's the code when we initialize them:
//Showing results
self.resultsTableController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
self.resultsTableController.tableView.delegate = self;
self.resultsTableController.tableView.dataSource = self;
self.resultsTableController.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
// Configuring searchController
self.searchController = [[RedactedNameSearchController alloc] initWithSearchResultsController:self.resultsTableController];
// When initialized with UISearchController, it works:
// self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsTableController];
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.delegate = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.delegate = self;
self.searchController.searchBar.delegate = self ;
UISearchController
subclass code:
@interface MySearchController () {
UISearchBar *searchBar;
}
@end
@implementation MySearchController
- (UISearchBar *)searchBar
{
if (searchBar == nil) {
searchBar = [[MySearchBar alloc] initWithFrame:CGRectZero];
searchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
}
return searchBar;
}
@end
`UISearchBar is implemented like so:
@implementation MySearchBar
-(void)setShowsCancelButton:(BOOL)showsCancelButton {
}
-(void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated {
}
@end