I am trying to get the new iOS-11 searchBar approach to work, but don't manage. The searchBar shows up, but is shown below the left bar button, instead of next to it:
It is the same in landscape mode. The code that I am using is:
self.searchResults = [[SearchResultsTable alloc] init];
self.searchResults.delegate = self;
searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResults];
searchController.searchResultsUpdater = self.searchResults;
searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(swapToListView:)];
if ([self.navigationItem respondsToSelector:@selector(setSearchController:)]) {
// only available from IOS-11 onwards
self.navigationItem.title = nil;
self.navigationItem.titleView = nil;
[self.navigationItem setSearchController:searchController];
} else {
// Fallback on earlier versions
self.navigationItem.titleView = searchController.searchBar;
}
The old code works fine on pre-iOS-11 systems, but has other problems on iOS-11, so I prefer to use the new approach. Anybody knows what I am doing wrong here?