UISearchBar disappears after events

I have a UISearchBar, in my opinion, contained within a UITableView, above the topmost cell. Everything works fine until I inject a new view controller into the navigation stack. As soon as I log out to a new VC and switch back to the original controller, the search bar does not appear on top of the table. Instead, there is a space between my nav and the top row of my table view. However, if I press that spacebar, the search bar opens as if it were there normally, and when I click the Cancel button, everything is fine.

I think somehow the UISearchBar view will be completely white, but I have no idea why. Initially, I just had the UISearchBar added to the storyboard as part of the UISearchDisplayController. How can I disallow the white search bar after my VC is unwound from a different controller than it was pushed onto the navigation stack?

+3


source to share


1 answer


I have the same problem. I don't think this has to do with the color of the search bar, but the layout of the search bar routine. After many trial and error, I came up with this solution:

@interface MySearchBar : UISearchBar
@end

@implementation MySearchBar

-(void) layoutSubviews
{
    [super layoutSubviews];
    if (self.subviews.count == 1)
    {
        UIView *subview = [self.subviews objectAtIndex:0];
        subview.frame = self.bounds;
    }
}

@end

      



Use MySearchBar instead of UISearchBar

+1


source







All Articles