Pregunta

I've been trying to fix this all day. My app has a night theme, but the problem happens when you touch in the area between the keyboard and UISearchBar after it shows it's results, because this doesn't trigger the UISearchBar's cancel method. Everything works fine for my app's day theme (normal) but the problem arises when trying to keep the status bar set to the default style. To restate: the problem happens like this: night mode enabled, type a letter in UISearchBar, it shows no results, user touches and scrolls on the table view which triggers the UISearchBar's did end editing method (keyboard then dismissed) and in turn makes the status bar the wrong style.

I appreciate any help offered!

Code:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];

    return YES;
}

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    if (appDelegate.nightThemeEnabled == NO)
    {
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
    }
    else
    {
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    }
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    if (appDelegate.nightThemeEnabled == NO)
    {
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
    }
    else
    {
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    }
}
¿Fue útil?

Solución

Solved this by using the answer provided on my other StackOverflow question: How to show a UISearchBar from top of screen for table view controller

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top