I almost had a mental breakdown, since I could not get the search bar to show in a new app project of mine. The search bar did not show up in the navigation controller, although I had done the following:
1) Add a "Search Bar and Search Display Controller" component to my storyboard view controller (in the bar below the view, not into the view)
2) In viewDidLoad, call "self.searchDisplayController.displaysSearchBarInNavigationBar = YES;"
The only thing that happened was that I got a label (!) that said Search.
After a looong time struggling, I created a new project and started to recreate the non-working one, piece by piece. I started with the storyboard...and now the search bar DID show. I then added libraries like Google Analytics, external components etc. Until the project was identical to the one that did not work...and now the problem was back! No search bar!
As I started to remove stuff, I finally found that it was a category code file (which I do not refer, but that is in the project) that is called UISearchBar+SearchField and which defines a readonly property.
The .h file looks like this:
@interface UISearchBar (SearchField2)
@property (nonatomic, readonly) UITextField *searchField;
@end
And the .m file looks like this
#import "UISearchBar+SearchField.h"
@implementation UISearchBar (SearchField)
- (UITextField *)searchField {
NSUInteger subViewCount = [self.subviews count];
for (int i = 0; i < subViewCount; i++) {
if ([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
return [self.subviews objectAtIndex:i];
}
}
return nil;
}
@end
As soon as I removed or renamed this property, everything started to work.
This is very(!) specific to my insanely strange problem, but perhaps it helps someone.