Bill Noto Bill Noto - 1 year ago 131
Objective-C Question

Why does the UISearchBar appear to have a strange flash when navigating back?

I've got a UISearchBar in my UINavigationItem's titleView associated with a UISearchController. When I navigate back, it appears to flash. Anyone seen this before?

vid of flash

@interface HNTileSearchViewController () <HNTileSearchResultsProtocol, SWRevealViewControllerDelegate, UISearchBarDelegate, HNSetSearchFiltersProtocol, HNKeywordResultsProtocol>
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, strong) UISearchBar * searchBarTop;

@implementation HNTileSearchViewController
- (void) customPreSetup {
HNKeywordResultsTableViewController * searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:HNKeywordResultsTableViewControllerStoryboardIdentifier];
searchResultsController.delegate = self;
_searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
_searchController.searchResultsUpdater = searchResultsController;
_searchController.hidesNavigationBarDuringPresentation = NO;
_searchController.dimsBackgroundDuringPresentation = NO;
_searchBarTop = _searchController.searchBar;
_searchBarTop.delegate = self;
_searchBarTop.placeholder = NSLocalizedString(@"Search heynay", nil);
_searchBarTop.showsCancelButton = NO;
_searchBarTop.showsScopeBar = NO;
self.navigationItem.titleView = _searchBarTop;
self.definesPresentationContext = YES;

- (void) viewDidLoad {
[super viewDidLoad];
[self customPreSetup];

Answer Source

I had the same problem and I solved in two ways:

First, you can put the searchStyle to Prominent:

searchController.searchBar.searchBarStyle = .Prominent

I wrote it in Swift by the way, the problem with this solution is that the search icon and the text, and the placeholder has a darker color and if the background is a darker color it looks bad.

The second solution I found is this:


 searchController.searchBar.searchBarStyle = .Prominent

The key is that both the navigation bar and the search bar isn't translucent and that both have the same color.

I hope this helps you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download