I would like to post a more specific question to this one.
I implemented a custom UISearchBar
, and thus a custom UISearchController
, as this seemed to be the only solution to stop the search bar from displaying a Cancel button. This indeed solved the mentioned problem, but created a new one. For some reason, the updateSearchResultsForSearchController:
delegate method (of the viewController
where I have implemented the searchController
) doesn't get called anymore (it does the first time I tap on the searchBar, but doesn't when the search string is being typed), while it does with a standard UISearchController
and UISearchBar
. As a result, the search results table fails to appear altogether.
Here is my code for SearchBar.h
@interface SearchBar : UISearchBar
@end
and SearchBar.m
#import "SearchBar.h"
@implementation SearchBar
- (void)setShowsCancelButton:(BOOL)showsCancelButton {
// Do nothing...
}
- (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated {
// Do nothing....
}
@end
as well as SearchController.h
@interface SearchController : UISearchController
@end
and SearchController.m
#import "SearchController.h"
#import "SearchBar.h"
@interface SearchController () {
SearchBar *_searchBar;
}
@end
@implementation SearchController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (SearchBar *)searchBar {
if (_searchBar == nil) {
_searchBar = [[SearchBar alloc] initWithFrame:CGRectZero];
}
return _searchBar;
}
@end
In MyViewController.h I subscribe to the following protocols:
@interface MyViewController : UIViewController <UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating>
Can anyone see what I may have missed? Thanks in advance.